【发布时间】:2013-01-24 07:02:51
【问题描述】:
我正在使用 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
我尝试了很多关联,但找不到合适的。
提案有一个 user_id 字段映射到用户 所以 Proposal.user 返回一个用户 用户然后有一个郊区ID,它返回一个郊区 Suburb 有一个名为 name 的字段,它返回一个字符串
我如何将其用于元搜索表单?
<%= f.text_field :user_user_suburb_name %>
or
<%= f.text_field :user_id_suburb_id_name %>
我无法得出一个可靠的结论。
提前感谢您的帮助。
【问题讨论】:
-
我知道它很简单,我只需要更深入地解释它是如何工作的,这样我就可以为其他参数推出它
标签: ruby-on-rails search meta-search