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 %>
我不能得出一個可靠的結論。
感謝您的幫助提前。
我知道它非常簡單,我只是需要更深入地解釋它是如何工作的,以便我可以將它展示給其他參數 – JamesWatling