Rails MetaSearch关联未定义的方法

时间:2013-01-24 07:02:52

标签: ruby-on-rails search meta-search

我正在使用rails应用程序,并开始使用元搜索处理搜索功能,但我在查找正确的搜索方法时遇到了麻烦。

例如,我有一个具有现场成本的模型(提案)。

..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

我尝试了许多协会,但找不到合适的协会。

Proposal有一个user_id字段,映射到用户 所以Proposal.user返回一个用户 然后用户有一个返回郊区的suburb_id 郊区有一个名为name的字段,它返回一个字符串

我如何将其用于元搜索形式?

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

我无法得出可靠的结论。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

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

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