I have a model named School
and I have a method called 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
How do I call it from a view with params like this:
School.custom_search params[:search], params[:page]
# or :
School.custom_search params[:search], params[:page], :desc
Do I use the link_to method?
# 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.