Reputation: 3003
say I have a text field like the following in a view called 'search':
<%= text_field_tag(:lookup) %>
how do I submit this ':lookup' value and pass it into the controller called 'search' and assign it to a variable?
It's a basic problem, but being a noob, it's difficult ;)
Upvotes: 17
Views: 18794
Reputation: 6436
That will be accessible in the controller as
params[:lookup]
Your controller could look something like this:
class SearchesController < ActionController::Base
def search
lookup = params[:lookup]
@models = Model.find_by_lookup(lookup)
end
end
And your view should look like this:
<%= form_tag searches_path do %>
<label for="lookup">Lookup</label>
<%= text_field_tag :lookup %>
<%= submit_tag "Submit" %>
<% end %>
Upvotes: 25