Forum: Ruby on Rails Help passing attributes

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
srj (Guest)
on 2008-12-04 20:40
(Received via mailing list)
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:
   <form id="registerForm2" method="post"

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

Can someone help with this?

Thank you
Thorsten M. (Guest)
on 2008-12-04 20:46
(Received via mailing list)
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
srj (Guest)
on 2008-12-04 23:06
(Received via mailing list)
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="<% %>" >
             . . .

In my controller, I do this:

  def register
    @user = User.create()

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?
Bharat R. (Guest)
on 2008-12-05 18:49
(Received via mailing list)
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.
This topic is locked and can not be replied to.