我有一个问题。我有一个show视图,它充当仪表板并从其他模型中引入记录,然后是与之关联的模型。我有一个简单的搜索表单,可以正常搜索一个模型,但我不知道如何通过它的相关模型查看它。我不认为全文搜索是必要的,我不确定它是如何工作的,因为我不想要在整个网站上搜索的东西。
由于
公司/显示/ 1
<div id="form">
<div class="search">
<% form_tag battalion_company_path, :method => :get do %>
<p>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
</p>
<% end %>
</div>
</div>
<div id="bc_box">
<% @soldiers.each do |soldier| %>
<div id="bc_focus">
<div class="right">
<%= link_to image_tag("../images/buttons/info.png", :border=>0), battalion_company_soldier_path(@battalion, @company,soldier) %>
<%= link_to image_tag("../images/buttons/edit.png", :border=>0), edit_battalion_company_soldier_path(@battalion, @company,soldier) %>
</div>
<%=h soldier.rank %> <%=h soldier.lastname %><br />
Cell: <%=h soldier.cellphone %><br />
<% soldier.primaries.each do |primary| %>
<p>
<%=h primary.firstname %> <%=h primary.lastname %> (<%=h primary.relationship %>)<br />
(c):<%=h primary.cellphone %><br />
<%=h primary.email %><br />
</p>
<% end %>
</div>
<% end %>
</div>
soldier.rb
def self.search(search)
if search
find(:all, :conditions => ['email LIKE ? OR lastname LIKE ? OR firstname LIKE ?', "%#{search}%", "%#{search}%", "%#{search}%"])
else
find(:all, :order => 'lastname')
end
end
companies_controller
@soldiers = @company.soldiers.search(params[:search])
@primary = @company.primaries.find(:all,:conditions => ["relationship = 'Spouse'"])