0

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?

1 Answers1

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
mathieugagne
  • 2,465
  • 1
  • 17
  • 18
  • does really work with what ever pathway? shouldnt I define a specfik path –  Feb 02 '13 at 21:47
  • And I get this error: undefined local variable or method `search' –  Feb 02 '13 at 21:54
  • This is all phony. It needs to match whatever you have in your application. I've updated with something that might worked. Again this is just to show you what it could be, no copy paste allowed here. – mathieugagne Feb 02 '13 at 21:59