简体   繁体   English

Rails MetaSearch关联未定义方法

[英]Rails MetaSearch Associations Undefined Method

I am working with a rails app and have begun to work on a search function using metasearch but I am having troubles getting the correct method for the search. 我正在使用Rails应用程序,并且已经开始使用metasearch进行搜索功能,但是在获取正确的搜索方法时遇到了麻烦。

For example I have a model (Proposal) that has a field cost. 例如,我有一个具有现场成本的模型(建议)。

..model/proposal.rb

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

For which this code works fine with meta search 对于此代码,它可以与元搜索一起很好地工作

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

Yet with a more complicated association I can not manage to get the meta search path correct. 但是,对于更复杂的关联,我无法正确设置元搜索路径。

I am trying to search over: 我正在尝试搜索:

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

I have tried many associations but cannot find the right one. 我尝试了许多协会,但找不到合适的协会。

Proposal has a user_id field which maps to user So Proposal.user returns a User User then has a suburb_id which returns a suburb Suburb has a field called name which returns a string 投标有一个user_id字段,该字段映射到用户,所以Proposal.user返回一个用户用户,然后有一个郊区_id,返回一个郊区郊区有一个名为name的字段,该字段返回一个字符串

How would I work this into a metasearch form? 我如何将其转化为元搜索形式?

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

I cannot come to a solid conclusion. 我不能得出确切的结论。

Thanks for your help in advance. 感谢您的帮助。

Was simply following the correct names as declared by the models. 只是遵循模型声明的正确名称。

Ie. 就是 in the model above, ensuring that it was User, not users etc. 在上面的模型中,确保它是用户,而不是用户等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM