[英]Rails MetaSearch Associations Undefined Method
我正在使用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返回一個用戶用戶,然后有一個郊區_id,返回一個郊區郊區有一個名為name的字段,該字段返回一個字符串
我如何將其轉化為元搜索形式?
<%= f.text_field :user_user_suburb_name %>
or
<%= f.text_field :user_id_suburb_id_name %>
我不能得出確切的結論。
感謝您的幫助。
只是遵循模型聲明的正確名稱。
就是 在上面的模型中,確保它是用戶,而不是用戶等。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.