rudolph9
rudolph9

Reputation: 8119

Creating a search input with Ruby on Rails

I am attempting to create a search form, the search is performed on third party site so there is no model just a controller. I have it set up as follows

views/items/index.html.haml :

= search_field :search, :search_input
= submit_tag 'Search'

views/items/search.html.haml:

[email protected] do |item|
  %h1= item.title

controllers/items_controller.rb:

def index
   #I am unsure of what to put in here?  I think
   #I need something wich sends @search_input to my search method
end

def search
   @items = some_third_party_search_method_i_wrote{ params[:search_input]}
end

How does one properly use the params object in rails? I don't understand how to get from the index page containing the search form to the search page containing the results of the search input?

Upvotes: 0

Views: 1143

Answers (1)

Dylan Markow
Dylan Markow

Reputation: 124409

You probably want to use search_field_tag instead since your form isn't tied to a model/object:

= search_field_tag :search_input

Then params[:search_input] should work.

Upvotes: 1

Related Questions