Search code examples
ruby-on-rails-4ruby-2.0friendly-id

friendly_id gem doesn't create slug


gem "friendly_id", "~> 5.0.4"

Model:

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

  def generated_slug
    title
  end
end

On save of the topic from the new action, the slug doesn't get created and on top of that, the URL goes to something like this: http://localhost:3000/topics/7 and the browser gives this: undefined method `friendly' for #

In addition, when I do this in the console:

Topic.create! title: "Joe Schmoe"

the slug column becomes nil.


Solution

  • I had another model with the same name overriding the friendly id behavior.