0

我有一个名为的模型School,我有一个名为custom_search

def self.custom_search( text, page, order = :asc )
    search( include: [:prices] ) do 
      fulltext text
      paginate page: page, per_page: 7
      order_by :price, order
    end
end

如何从具有如下参数的视图中调用它:

School.custom_search params[:search], params[:page]
# or :
School.custom_search params[:search], params[:page], :desc

我是否使用 link_to 方法?

4

1 回答 1

1
# app/controllers/schools_controller.rb
def search
  @schools = School.custom_search params[:search], params[:page]
end

# in your view
link_to 'My link', search_schools_path(search: 'Bar', page: 1)

# config/routes.rb
resources :schools do
  collection do
    get 'search'
  end
end
于 2013-02-02T21:35:35.477 回答