我有一个名为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方法?
答案 0 :(得分:0)
# 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