I have a rails app that uses the FriendlyId gem and recently I've started to get NoMethodErrors in development and test. This problem has only started recently and we're a couple of iterations into the project ('staging' which is on heroku is still working).
The problem occurs on creating a new record of any model that is setup for friendly Id's. Here's one of those models:
class Playlist < ActiveRecord::Base
attr_accessible :title, :drill_tokens, :program, :order , :get_playlists
validates_presence_of :title
validates_uniqueness_of :title
has_many :playlist_items, :dependent => :destroy, :order => :id
has_many :drills, :through => :playlist_items
attr_reader :drill_tokens
attr_reader :get_playlists
def drill_tokens=(ids)
self.drill_ids = ids.split(",")
end
has_friendly_id :title, :use_slug => true
end
The error I receive when my tests run is NoMethodError in PlaylistsController#create the body of the error message is this:
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
And the trace starts here:
friendly_id (3.2.1.1) lib/friendly_id/active_record_adapter/slug.rb:53:in `enable_name_reversion'
activesupport (3.0.7) lib/active_support/callbacks.rb:415:in `_run_save_callbacks'
开发者_如何学C
I've confirmed it is related to the friendly_id gem, as commenting out the 'has friendly_id' line and the create call works again. I've also tried the related rake tasks: running
rake friendly_id:redo_slugs MODEL=playlist
gives me the same error. Alternately, running a down-migration on the slugs table and re-running rails g friendly_id and the up-migration, then running
rake friendly_id:make_slugs MODEL=playlist
totally kills the table, and from then on just trying the playlist#show action gives the same error.
Hope this is enough detail. I am thoroughly confused as to how to get back to the working state.
精彩评论