# Help passing attributes

**URL:** <https://www.ruby-forum.com/t/help-passing-attributes/154881>\
**Category:** Rails\
**Created:** [December 4, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/help-passing-attributes/154881 "2008-12-04T19:40:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [December 4, 2008, 7:40pm UTC](https://www.ruby-forum.com/t/help-passing-attributes/154881/1 "2008-12-04T19:40:59Z")

</div>

I know this is a really basic and simple thing for Rails, but as a  
newbie, I am having trouble figuring it out . . .

I have a home page with a register link which executes the register  
action and shows the first (of two) registration page. When I click  
the “Continue” button, I want to go to the “continue\_registration”  
action which will take the data from the first form and create the  
user object. That part works as planned. However, the second form  
has all the optional fields (home address, phone, etc.). The  
questionI have is how do I pass the user id (or the user model) from  
the register action to the continue\_registration action?

I have a form on the second page using this code:

But in the completeRegistration action, the params hash does not have  
any reference to my user id.

Can someone help with this?

Thank you

---

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [December 4, 2008, 7:46pm UTC](https://www.ruby-forum.com/t/help-passing-attributes/154881/2 "2008-12-04T19:46:16Z")

</div>

Ok, so in action continue\_registraton you have this user\_id  
It should be part of the second form, so it is handed over to the  
third one.  
Commonly that’s done with a hidden field in the second form:

(assuming, it’s in params[:user\_id])  
\<%= f.hidden\_field :user\_id, :value =\> params[:user\_id] %\>

just replace params[:user\_id] with the variable holding it,  
if it’s not in params hash

---

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [December 4, 2008, 10:06pm UTC](https://www.ruby-forum.com/t/help-passing-attributes/154881/3 "2008-12-04T22:06:43Z")

</div>

I was trying something like that. My first form starts with:

```
 <form id="registerForm" method="post" action="register02">
        <input type="hidden" name="passedUser" id="passedUser"

```

value="\<% @user.id %\>" \>  
. . .

In my controller, I do this:

def register  
@user = User.create()  
end

But when I inspect (using NetBeans debugger) the params hash,  
passedUser is an empty string. I was expecting the User ID (42, or  
whatever number is assigned by the database)

What am I missing?

---

<div class="post-metadata">

**Author:** ![srj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@srj](https://www.ruby-forum.com/u/srj)\
**Post date:** [December 5, 2008, 5:49pm UTC](https://www.ruby-forum.com/t/help-passing-attributes/154881/4 "2008-12-05T17:49:50Z")

</div>

You can put the user\_id in Rails flash which will remember it for  
only the next request and then automatically discard it. Your next  
request is the “continue\_registration” so you can do whatever you want  
with it. As a matter of fact, you can pretty much put all the user  
data from the first form in it so that you have access to it in the  
second form. Flash only remembers the data stored in it for the next  
request and then is automatically cleared by rails. I would not put  
it in session since you will have to manually clean it.  
Bharat
