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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 May 3, 2007, at 7:05 PM, Dave A. wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 5/4/07, Dave A. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > 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. > > DaveTo get access to parameters you need to use the params method def testing @bar = param[:foo] end Cheers --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> def testing > @bar = param[:foo] > end >Thanks to both of you! Worked perfectly. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---