views:

126

answers:

2

Hi,

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 ;)

+2  A: 

That will be accessible in the controller as

params[:lookup]

Your controller cloud look something like this:

class SearchesController < ActionController::Base

  def search
    lookup = params[:lookup]
    @models = Model.find_by_lookup(lookup)
  end
end

And your view likes this:

<% form_tag searches_path do %>
  <label for="lookup">Lookup</label>
  <%= text_field_tag :lookup %>
 <%= submit_tag "Submit" %>
<% end %>
erik
I forgot to mention in the question, but how do I submit the form?
mr.flow3r
ohhh i see thanks :)
mr.flow3r
arrg I must be stupid today. Am I supposed to create a controller file called searches_controller.rb?
mr.flow3r
Yes. If you're just getting started using scaffolding as an example might help. http://fairleads.blogspot.com/2007/12/rails-20-and-scaffolding-step-by-step.html
Andy Gaskell
+2  A: 

This guide is sweeeeeet for form info - I use it all the time. :)

http://guides.rubyonrails.org/form%5Fhelpers.html

cakeforcerberus