Rails Meta_Search:在关联模型的显示页面中搜索

时间:2012-08-26 12:11:00

标签: ruby-on-rails model-associations meta-search

我有一个模型trip.rb

 class Trip < ActiveRecord::Base
    has_and_belongs_to_many :categories
 end

我正在使用meta_search在其索引页面上搜索旅行。

  <%= form_for @search do |f| %>             

     <%= f.collection_select :location_id_equals, Location.order('country ASC').all, :id, :name, :include_blank => true, :prompt => "All locations" %> 

     <%= f.collection_select :categories_id_equals, Category.all, :id, :name, :include_blank => true, :prompt => "All categories"  %> 

     <%= f.collection_select :budget_id_in, Budget.all, :id, :name, :include_blank => true, :prompt => "All budgets" %> 

     <%= submit_tag "Find", :class => "btn btn-primary btn-large" %> </li>

  <% end %>

trips_controller.rb

  def index   
    @search = Trip.search(params[:search])  
  end 

Category.rb

class Category < ActiveRecord::Base
  has_and_belongs_to_many :trips
end

现在我想在类别显示页面上添加搜索,并在那里搜索相关的旅行。

问题是我不是专家,也不确定如何正确地做到这一点。

有人指向正确的方向吗? 感谢。

0 个答案:

没有答案