Saiho Yuen
2005-Nov-09 14:55 UTC
how to get information stored in a form by using ruby-rails
Hi, I''m a newbie with ruby-rails (also with web developpement) I want to create a form to get data from the user, like text field and combobax, button, etc. I used "text_field_tag" or other "tag" to genenate those components on the html, but after that I have no idea how to get the data from the components, I read the examples and documentations about how to create the componenets, but I didn''t find anything which talk about how to extract them... Can someone please tell me how to do it or where can I find the documentation!!! Thanks you very much!!!! sayoyo __________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com
Duane Johnson
2005-Nov-09 19:47 UTC
Re: how to get information stored in a form by using ruby-rails
On Nov 9, 2005, at 7:55 AM, Saiho Yuen wrote:> Hi, > > I''m a newbie with ruby-rails (also with web > developpement) I want to create a form to get data > from the user, like text field and combobax, button, > etc. I used "text_field_tag" or other "tag" to > genenate those components on the html, but after that > I have no idea how to get the data from the > components, I read the examples and documentations > about how to create the componenets, but I didn''t find > anything which talk about how to extract them... Can > someone please tell me how to do it or where can I > find the documentation!!!Is there any particular reason you''re using ''tag'' and ''text_field_tag''? It''s usually much simpler to use the form helpers. For example, in a view such as edit.rhtml: <%= text_field ''user'', ''name'' %> and then in your controller you could access the user''s name via: def edit @name = params[:user][:name] end If you need further help, perhaps you can be more specific with your question or show examples of what you''ve already tried and why. Duane Johnson (canadaduane)
Saiho Yuen
2005-Nov-09 20:39 UTC
Re: how to get information stored in a form by using ruby-rails
Hi, the reason I use "_tag" is because I don''t have a model (no database) If I understand well the mecanism, the helpers without "tag", they send information directly to the model...so that''s why I didn''t used them. After a lot of tryings, I find out that I can get the info from the variable "@params", like "@params[''post''], but I don''t know if it is the correct way to get the information. Thanks you very much sayoyo this is an example. def buildTable if @params.include?(''post'') then @checkTextField = @params[''post''] else @checkTextField = nil end end buildTable.rhtml <html> <head> <title>Build Table</title> </head> <body> <%= start_form_tag :action => :buildTable %> <br> <%= text_field_tag(name = "post", nil, "size" => "20", "maxsize"=>"20") %> <br> <%= submit_tag(value = "run") %> <%= submit_tag(value = "cancel") %><br> <%= end_form_tag %> <%= @checkTextField %> <%= debug(@params) %> </body> </html> --- Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Nov 9, 2005, at 7:55 AM, Saiho Yuen wrote: > > > Hi, > > > > I''m a newbie with ruby-rails (also with web > > developpement) I want to create a form to get data > > from the user, like text field and combobax, > button, > > etc. I used "text_field_tag" or other "tag" to > > genenate those components on the html, but after > that > > I have no idea how to get the data from the > > components, I read the examples and documentations > > about how to create the componenets, but I didn''t > find > > anything which talk about how to extract them... > Can > > someone please tell me how to do it or where can I > > find the documentation!!! > > Is there any particular reason you''re using ''tag'' > and > ''text_field_tag''? It''s usually much simpler to use > the form > helpers. For example, in a view such as edit.rhtml: > > <%= text_field ''user'', ''name'' %> > > and then in your controller you could access the > user''s name via: > > def edit > @name = params[:user][:name] > end > > If you need further help, perhaps you can be more > specific with your > question or show examples of what you''ve already > tried and why. > > Duane Johnson > (canadaduane) > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >__________________________________ Yahoo! FareChase: Search multiple travel sites in one click. http://farechase.yahoo.com
Duane Johnson
2005-Nov-10 22:42 UTC
Re: how to get information stored in a form by using ruby-rails
On Nov 9, 2005, at 1:39 PM, Saiho Yuen wrote:> Hi, > > the reason I use "_tag" is because I don''t have a > model (no database) If I understand well the mecanism, > the helpers without "tag", they send information > directly to the model...so that''s why I didn''t used > them. > > After a lot of tryings, I find out that I can get the > info from the variable "@params", like > "@params[''post''], but I don''t know if it is the > correct way to get the information. > > Thanks you very much >No problem. Some comments about the code below...> def buildTable > if @params.include?(''post'') then > @checkTextField = @params[''post''] > else > @checkTextField = nil > end > endThis method could be simplified, like this: def buildTable @checkTextField = params[:post] end If there is no ''post'' key in the params hash, then it will be nil by default so there''s no need to add the conditional statement.> > buildTable.rhtml > <html> > <head> > <title>Build Table</title> > </head> > <body> > <%= start_form_tag :action => :buildTable %> <br> >You may consider using the convention of underscores instead of camelCase, e.g.: start_form_tag :action => build_table. It''s a Ruby convention that Rails sometimes relies on for conversion between camelCase and underscored variables.> <%= text_field_tag(name = "post", nil, "size" => > "20", "maxsize"=>"20") %> <br> > > <%= submit_tag(value = "run") %> > <%= submit_tag(value = "cancel") %><br>The above two lines look a little odd to me... you''re assigning the variable called ''value'' twice, but then not using it below. Perhaps you meant to use a symbol-as-key hash like this: submit_tag(:value => "run") submit_tag(:value => "cancel") Good luck! Duane Johnson (canadaduane)