How to access param entered through text_field

I’m rendering partial a form comprising several text_field helpers to
maintain my User model. For example, the email field is:

Email
<%= text_field 'user', 'email', :size => '40', :maxsize => '256' %>

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

Lindsay B. wrote:

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 with the name user[email]. The
square brackets get parsed and turned into hashes by Rails.


Philip R.
http://tzinfo.rubyforge.org/ – DST-aware timezone library for Ruby

The square brackets get parsed and turned into hashes by Rails.

Thanks Philip - I think I understand it now.