【问题标题】:friendly_id gem doesn't create slugfriendly_id gem 不会产生 slug
【发布时间】:2015-07-30 07:25:14
【问题描述】:
gem "friendly_id", "~> 5.0.4"

型号:

class Topic < Activerecord::Base
  extend FriendlyId
  friendly_id :generated_slug, use: [:slugged, :history]

  def generated_slug
    title
  end
end

在从新操作中保存主题时,不会创建 slug,最重要的是,URL 会变成这样:http://localhost:3000/topics/7,浏览器会给出这个:undefined method `friendly' for #

此外,当我在控制台中执行此操作时:

Topic.create! title: "Joe Schmoe"

slug 列变为 nil。

【问题讨论】:

  • class Topic &lt; ActiveRecord::Base extend FriendlyId friendly_id :title, use: :slugged end User.create!标题:“乔·施莫”

标签: ruby-on-rails-4 ruby-2.0 friendly-id


【解决方案1】:

我有另一个同名的模型覆盖了友好的 id 行为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-20
    • 2018-03-22
    • 2015-12-27
    • 2014-10-22
    • 2012-02-28
    • 2015-02-12
    • 2018-07-15
    • 2014-03-19
    相关资源
    最近更新 更多