american-ninja-warrior
american-ninja-warrior

Reputation: 8185

how to fix undefined method `find_by_friendly_id'

I'm trying this

Opportunity.find_by_friendly_id(params[:id])

inside a rails application with friendly_id configured. I get

undefined method `find_by_friendly_id' for #<Class:0x007f8060395ca0> Did you mean? find_by_sql

Interestingly, this works:

Opportunity.friendly.find(params[:id])

Whats going on?

Here's the docs from https://github.com/norman/friendly_id/blob/master/lib/friendly_id/finder_methods.rb

# If you want to search only by the friendly id, use {#find_by_friendly_id}.
# @raise ActiveRecord::RecordNotFound

update: someone wanted to see this:

$ cat components/core/app/models/opportunity.rb | grep friendly
  friendly_id :slug_candidates, use: :slugged
$

Upvotes: 0

Views: 274

Answers (1)

american-ninja-warrior
american-ninja-warrior

Reputation: 8185

I ended up adding finders to the model

friendly_id :foo, :use => [:slugged, :finders]

Upvotes: 1

Related Questions