Hi there! I'm a bit of a rails newbie, and I've had success as long as I followed rails conventions and used the form helpers. But now I want to do something a little different and I'm already stumped. I want to pass some form data into the controller, but it's not related to a database model or anything like that. Here's what I have in my view: <%= start_form_tag :action => 'testing' %> <input type="text" name="foo" /> <%= submit_tag "Create" %> <%= end_form_tag %> I guess I'm not sure how to access the form data named "foo" in the controller. Is it something sort of like this: def testing(foo) @bar = foo end Thanks for the help in advanced. I'm guessing this is pretty simple, but I'm new to ruby, rails, and programming in general. Dave
on 2007-05-04 04:05
on 2007-05-04 04:10
Here's what belongs in your controller: def testing @bar = params[:foo] end You should change your view not to user start_form_tag...end_form_tag, it's deprecated. Here's how instead: <% form_tag :action=> 'testing' do %> ... <% end %> Notice those are in <% %>, not <%= %>. Andy
on 2007-05-04 04:12
On 5/4/07, Dave A. <email@example.com> wrote: > <%= start_form_tag :action => 'testing' %> > > Thanks for the help in advanced. I'm guessing this is pretty simple, but > I'm new to ruby, rails, and programming in general. > > Dave To get access to parameters you need to use the params method def testing @bar = param[:foo] end Cheers
on 2007-05-04 04:20
> def testing > @bar = param[:foo] > end > Thanks to both of you! Worked perfectly.