Rails Search Across Multiple Models -
i have issue. have show view acts dashboard , brings in records other models , models associated that. have simple search form working fine search through 1 model, don't know how have through associated models well. don't think full text search necessary , not sure how work because don't want going search across whole site.
thanks
companies/show/1
<div id="form"> <div class="search"> <% form_tag battalion_company_path, :method => :get %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "search", :name => nil %> </p> <% end %> </div> </div> <div id="bc_box"> <% @soldiers.each |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 |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 ? or lastname ? or firstname ?', "%#{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'"])
how search engine behind app such thinking sphinx ? leave hard work of caching , searching else , let rails app serve result.
Comments
Post a Comment