Question

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:inmethod_missing' friendly_id (5.0.1) lib/friendly_id/slugged.rb:302:in scope_for_slug_generator' friendly_id (5.0.1) lib/friendly_id/history.rb:104:inscope_for_slug_generator' friendly_id (5.0.1) lib/friendly_id/slugged.rb:313:in slug_generator' friendly_id (5.0.1) lib/friendly_id/slugged.rb:294:inset_slug'

Looks like the error is on line 302 of slugged.rb:

scope = scope.friendly unless friendly_id_config.uses? :finders
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top