I''m rendering partial a form comprising several text_field helpers to maintain my User model. For example, the email field is: <p><label for="user_email">Email</label><br/> <%= text_field ''user'', ''email'', :size => ''40'', :maxsize => ''256'' %></p> In my controller, I know I can assign all the params in the form to my user object with ''@user = User.new(params[:user])'', but how can I assign individual params? Say I wanted to set the variable email to be the contents of the above field. I could recode the partial into pure HTML then assign params(''email'') to my variable, but I would rather stick with the RoR helpers as it looks cleaner. Lindsay -- Posted via http://www.ruby-forum.com/.
Philip Ross
2006-Feb-25 13:09 UTC
[Rails] Re: How to access param entered through text_field
Lindsay Boyd wrote:> I''m rendering partial a form comprising several text_field helpers to > maintain my User model. For example, the email field is: > > <p><label for="user_email">Email</label><br/> > <%= text_field ''user'', ''email'', :size => ''40'', :maxsize => ''256'' > %></p> > > In my controller, I know I can assign all the params in the form to my > user object with ''@user = User.new(params[:user])'', but how can I assign > individual params? Say I wanted to set the variable email to be the > contents of the above field. I could recode the partial into pure HTML > then assign params(''email'') to my variable, but I would rather stick > with the RoR helpers as it looks cleaner.You can leave the partial as it is and use: email = params[:user][:email] text_field will generate an <input> with the name user[email]. The square brackets get parsed and turned into hashes by Rails. -- Philip Ross http://tzinfo.rubyforge.org/ -- DST-aware timezone library for Ruby