1

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
nullnullnull
  • 8,039
  • 12
  • 55
  • 107

1 Answers1

2

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

bonyiii
  • 2,833
  • 29
  • 25
  • Thank you, that's definitely the cause of the bug. Unfortunately, this solution isn't viable in my use-case, as the other models that inherent from Official should not have friendly ids. Still, it's good know what's going on. – nullnullnull Nov 30 '13 at 17:21
  • Actually, it looks like the link you provided has some suggestions for how to handle this. Got everything working with that hint. – nullnullnull Nov 30 '13 at 19:11