cedric
cedric

Reputation: 223

NameError: uninitialized constant with FriendlyId after migration to Rails4

I just migrated to Rails4 from 3.12 and I use FriendlyId, which was working fine in Rails 3.12 I followed the instructions I found here http://richonrails.com/articles/friendlyid-and-rails-4#.U6fTOY1_v_4

so my gemfile features:

gem 'friendly_id', '~> 5.0.0'

Using friendly_id 5.0.4

But I keep getting the following error message:

NameError: uninitialized constant <Classname>::FriendlyId

for each Class that resorts to FriendlyId

I saw this NameError in SongsController#index uninitialized constant Song::FriendlyId But in my case, bundle install doesn't change anything

Upvotes: 2

Views: 3198

Answers (4)

user9651624
user9651624

Reputation:

make sure you restart the console after bundling.

Upvotes: 4

Bella
Bella

Reputation: 360

I had same issue and in my case I forgot this step:

# Change User.find to User.friendly.find in your controller
User.friendly.find(params[:id])

Upvotes: 1

wuliwong
wuliwong

Reputation: 4368

Not completely sure without seeing your code but you need to add extend FriendlyId to your model.

class Song < ActiveRecord::Base
  extend FriendlyId
  friendly_id :foo, use [:slugged, :finders]
end

In this example :foo is the attribute you want friendly_id to use to create the unique slug.

Upvotes: 0

Chris O&#39;Sullivan
Chris O&#39;Sullivan

Reputation: 1272

I had this same problem with Rails 4 - and I fixed it by restarting spring:

$ spring stop

I ran the console again and it went back to working.

Upvotes: 6

Related Questions