Forum: Ruby on Rails How to access param entered through text_field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-02-25 13:39
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
9ab183bb240ffd3a3966d5a615b4bdeb?d=identicon&s=25 Philip Ross (Guest)
on 2006-02-25 14:10
(Received via mailing list)
Lindsay Boyd 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 <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
Ae03102311939454d2b7f1ca3139fd97?d=identicon&s=25 Lindsay Boyd (Guest)
on 2006-02-25 14:35
> The square brackets get parsed and turned into hashes by Rails.

Thanks Philip -  I think I understand it now.
This topic is locked and can not be replied to.