2013-01-24 37 views
0

我正在使用rails应用程序,并已开始使用元搜索功能对搜索功能进行操作,但我遇到了麻烦,无法获取正确的搜索方法。Rails MetaSearch关联未定义方法

例如,我有一个模型(建议),有一个字段的成本。

..model/proposal.rb 

class Proposal < ActiveRecord::Base 
belongs_to :user 
has_many :users, :through => :invitations 
attr_accessible :cost, :user_id 

对于此代码工作正常使用的元搜索

..views/homes/live_requests.html.erb 

<%= form_for @search, :url => "/live_requests", :html => {:method => :get} do | 
<%= f.label :cost_greater_than %> 
<%= f.text_field :cost_greater_than %><br /> 
<!-- etc... --> 
<%= f.submit %> 

然而,随着更复杂的关联,我不能设法得到的元搜索路径是正确的。

我试图寻找过:

Proposal.last.user.suburb.name #Returns the name of the suburb as expected 

我已经尝试了许多关联,但无法找到合适的人。

提案映射到用户USER_ID场 所以Proposal.user然后返回用户 用户有suburb_id返回郊区 郊区有一个字段名为name并返回一个字符串

我怎么会工作这成一个元搜索的形式?

<%= f.text_field :user_user_suburb_name %> 
or 
<%= f.text_field :user_id_suburb_id_name %> 

我不能得出一个可靠的结论。

感谢您的帮助提前。

+0

我知道它非常简单,我只是需要更深入地解释它是如何工作的,以便我可以将它展示给其他参数 – JamesWatling

回答

0

只是遵循模型声明的正确名称。

即,在上面的模型中,确保它是用户,而不是用户等。

相关问题