Forum: Ruby on Rails Passing text from an rhtml input to a controller

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Barry Sperling (Guest)
on 2006-05-17 02:29
Hello,
     I would like to allow people to type some text into a webpage and
then have that text passed to the controller (e.g. for use by a search
routine).  The following code has an input box in a form.  What would I
put in the "title" parameter to have that passed to the controller?
When I put in a constant string it works but when I put in things like
searcher.search_title.value or document.searcher.search_title.value the
error text complains about the first word I use.  What would go where
the ???? is?

<form name="searcher">
   <input style="font-size:20" size="50" name="search_title" type="text"
value=""/>

   <table>
      <td>
         <%= link_to "search",
              :action => "list",
              :title => ????
         %>
      </td>
   </table>
</form>

I have the "Agile Development" and "Pragmatic Programmer" books but have
read less than half of each.  Much more to learn, but the above problem
may be an HTML one.
     Thanks,
         Barry
Dorian M. (Guest)
on 2006-05-17 05:26
(Received via mailing list)
if I understand right, you want to capture a value dynamically from the
DOM yes?
what do you actually need to do?

>From what I can see, you will already be passing the search_title back to the form from 
the <input>. you can access this value in the controller using @params[:search_title], but 
you haven't yet set a form action.

The values you specified as not working are DOM elements, and as such
will only have any meaning or value *after* the template has been served
and rendered by the browser. In which case you should use one of the
javascript helper functions(like observe_field or observe_form).

check the API docs for help with these:
http://api.rubyonrails.org/

dorian
This topic is locked and can not be replied to.