# Quick question about @params

**URL:** <https://www.ruby-forum.com/t/quick-question-about-params/54412>\
**Category:** Rails\
**Created:** [March 4, 2006, 12:53am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412 "2006-03-04T00:53:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_Teng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a5b964/32.png) [@Daniel\_Teng](https://www.ruby-forum.com/u/Daniel_Teng)\
**Post date:** [March 4, 2006, 12:53am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412/1 "2006-03-04T00:53:22Z")

</div>

I was looking through the loginGenerator code and noticed the following:

Login:  
User.authenticate(@params[:user\_login], @params[:user\_password])

Signup  
User.authenticate(@user.login, @params[:user][:password])

The syntax of the call in the signup code confused me…what exactly  
does @params[:user][:password] this return to me? Is the params  
structure a multi-dimensional array? I would have thought that the  
login and signup use of params would be the same.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![Daniel\_Teng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a5b964/32.png) [@Daniel\_Teng](https://www.ruby-forum.com/u/Daniel_Teng)\
**Post date:** [March 4, 2006, 1:49am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412/2 "2006-03-04T01:49:53Z")

</div>

Daniel Teng wrote:

> I was looking through the loginGenerator code and noticed the following:
> 
> Login:  
> User.authenticate(@params[:user\_login], @params[:user\_password])
> 
> Signup  
> User.authenticate(@user.login, @params[:user][:password])
> 
> The syntax of the call in the signup code confused me…what exactly  
> does @params[:user][:password] this return to me? Is the params  
> structure a multi-dimensional array? I would have thought that the  
> login and signup use of params would be the same.
> 
> Thanks in advance

@params[:user][:password] is a hash within a hash. It says, get me the  
value for password in the user hash.

I am not very familiar with the specific example in the LoginGenerator  
code. @params[:user\_login] is going to return you the value for the key  
:user\_login in the @params hash.

Gareth

---

<div class="post-metadata">

**Author:** ![Daniel\_Teng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a5b964/32.png) [@Daniel\_Teng](https://www.ruby-forum.com/u/Daniel_Teng)\
**Post date:** [March 5, 2006, 6:37am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412/3 "2006-03-05T06:37:32Z")

</div>

Thanks! I was a bit confused, being a newcomer to the environment, when  
I expected the syntax to read something more like:

@user = @params[:user]  
@password = @user.password

I didn’t realize that the password was represented as a hash within the  
user object.

Regards  
Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_Teng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a5b964/32.png) [@Daniel\_Teng](https://www.ruby-forum.com/u/Daniel_Teng)\
**Post date:** [March 5, 2006, 8:10am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412/4 "2006-03-05T08:10:52Z")

</div>

Daniel Teng wrote:

> Thanks! I was a bit confused, being a newcomer to the environment, when  
> I expected the syntax to read something more like:
> 
> @user = @params[:user]  
> @password = @user.password
> 
> I didn’t realize that the password was represented as a hash within the  
> user object.

I wouldn’t say “the password was represented as a hash within the user  
object”. The  
password’s not a hash, it’s a field within user.

But, if you look at the generated html for your login page, you’ll see  
that the “name”  
attribute on the input tag for your password field is “user[password]”.  
That notation  
tells rails to create a hash under the key “user” in the params hash.

In that hash, there are string values under keys like “password”,  
“login”, etc. These are  
the values that are going to go in the user object. So, that notation is  
a way of grouping  
together the input params that are going to go into some model object.

And, it allows one to say things like “User.new(@params[:user])” because  
that’ll pass  
everything in the “user” param hash into the constructor (which can be a  
little dangerous  
btw… someone can start playing around with submitting  
“user[something]” combinations…).

And in the case you were looking at, the password was submitted as  
user[password], so  
rails puts that in a :user hash, so you need to do  
@params[:user][:password] to get the  
user hash and then the value for password within that.

Hope that makes things a little clearer.

b

---

<div class="post-metadata">

**Author:** ![Daniel\_Teng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a5b964/32.png) [@Daniel\_Teng](https://www.ruby-forum.com/u/Daniel_Teng)\
**Post date:** [March 7, 2006, 1:04am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412/5 "2006-03-07T01:04:56Z")

</div>

That was a great detailed explanation of how it works. Is this behavior  
documented somewhere in the official guides? I’d like to know where I  
can read up on this before posting to the group.

Daniel

---

<div class="post-metadata">

**Author:** ![Daniel\_Teng](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/a5b964/32.png) [@Daniel\_Teng](https://www.ruby-forum.com/u/Daniel_Teng)\
**Post date:** [March 7, 2006, 6:31am UTC](https://www.ruby-forum.com/t/quick-question-about-params/54412/6 "2006-03-07T06:31:06Z")

</div>

Well, I hate to tell you to buy a book, but Agile Web D. with  
Rails is pretty  
indispensible when you’re starting out (and I’m just barely past that).  
The first chapter  
is pretty hand-holding, though I don’t know that it gets into the params  
stuff. I have  
that and the “Pickaxe” book (Programming Ruby, also by Dave T.). I  
gave myself the  
time to read large chunks of these and played with examples and it  
started to gel. Sorry  
if that’s not the most helpful answer… but you just have to give  
yourself some time.  
That and ask questions here… it’s great to have this active a list!

b
