Reputation: 8189
I recently installed friendly_id
5 on my Rails 4 app. I've followed the quick start guide, and setup a model like this:
class Official::Master < Official
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
end
When I try to save an Official::Master, however, I get this error:
undefined method `friendly' for #<ActiveRecord::Relation []>
This happens in the create
controller action:
def create
official = Official::Master.new(official_params)
official.save # error occurs on this line
end
Unfortunately, Rails isn't producing a stack trace, which it typically does. I'm at a loss for how to troubleshoot this error.
UPDATE:
Removed the backtrace silencers and got this:
activerecord (4.0.1) lib/active_record/relation/delegation.rb:121:in
method_missing' activerecord (4.0.1) lib/active_record/relation/delegation.rb:68:in
method_missing' friendly_id (5.0.1) lib/friendly_id/slugged.rb:302:inscope_for_slug_generator' friendly_id (5.0.1) lib/friendly_id/history.rb:104:in
scope_for_slug_generator' friendly_id (5.0.1) lib/friendly_id/slugged.rb:313:inslug_generator' friendly_id (5.0.1) lib/friendly_id/slugged.rb:294:in
set_slug'
Looks like the error is on line 302 of slugged.rb:
scope = scope.friendly unless friendly_id_config.uses? :finders
Upvotes: 1
Views: 2304
Reputation: 2883
It is seems that friendlyid 5 not yet handling single table inheritance in rails 4 correctly. What happens if you put the code below to the parent class?
extend FriendlyId
friendly_id :name, use: [:slugged, :history]
And here is an issue that address more or less the same problem: Friendly_id 5 rc1 - single table inheritance issue
Upvotes: 2