Barry Sperling
2006-May-16 22:30 UTC
[Rails] Passing text from an rhtml input to a controller
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 -- Posted via http://www.ruby-forum.com/.
Dorian Mcfarland
2006-May-17 01:24 UTC
[Rails] Passing text from an rhtml input to a controller
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 Barry Sperling wrote:> 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 >-- -- I do things for love or money