2017-08-04 61 views
0

我想這如何解決未定義的方法`find_by_friendly_id」

Opportunity.find_by_friendly_id(params[:id]) 

與friendly_id Rails應用程序配置裏面。我得到

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

有趣的是,這個工程:

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

回事請告訴我?

下面是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 

更新文檔:有人想看到這一點:

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

HTTPS:/ /github.com/norman/friendly_id/issues/701#issuecomment-142669074。我可以用這種方法 –

+0

http://www.rubydoc.info/github/norman/friendly_id/FriendlyId%2FFinderMethods%3Afind_by_friendly_id –

+0

爲什麼在這個問題上有-1票,最近怎麼回事...... –

回答

0

我結束了根據加入finders到模型

friendly_id :foo, :use => [:slugged, :finders] 
相關問題