# Passing variables through session

**URL:** <https://www.ruby-forum.com/t/passing-variables-through-session/138675>\
**Category:** Rails\
**Created:** [May 26, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/passing-variables-through-session/138675 "2008-05-26T16:14:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jens](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/d2c977/32.png) [@jens](https://www.ruby-forum.com/u/jens)\
**Post date:** [May 26, 2008, 4:14pm UTC](https://www.ruby-forum.com/t/passing-variables-through-session/138675/1 "2008-05-26T16:14:03Z")

</div>

Hi

I have a form with user details and credit card details.The user  
details are entering into ‘user’ table and credit card details are  
entering ‘creditcard’ table.As the user entered his personnel  
information and credit card details and click on submit button the  
page posts all the variables into next page where user can conform his  
details.By clicking on conform only the data are being entered into  
user table and creditcard table. I need to pass the information from  
one page to next as session varibles? can anyone please help me.

My code is like this in regiter\_page(1stpage)  
\<% form\_for :user, @user, :url =\> {:controller =\> “users”, :action =\>  
“register\_paid\_user” } do |user| %\>

  
  
  
  
  

| ![Payment Information](https://test.ruby-forum.com/images/inner-table/%0Apayment-information.gif) | &nbsp; &nbsp; |

  
  
  
  
  
  
  
  
  
  
  
  
  

```
          </table>
        <table width="100%" border="0" cellpadding="0"

```

cellspacing=“0” class=“inner\_tablemrg”\>

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  

| User Information\</  
th\>  
 | &nbsp; |
| --- | --- |
| First Name:\</  
td\>  
 | \<%=  
user.text\_field :first\_name, :class =\> “formfield”, :size =\> “20” %\>\</  
td\>  
 |
| Last Name: | \<%=  
user.text\_field :last\_name, :class =\> “formfield”, :size =\> “20” %\> \</  
td\>  
 |
| Email  
Address: | \<%=  
user.text\_field :email, :class =\> “formfield”, :size =\> “20” %\> |
| Billing Name and  
Address | &nbsp; |
| --- | --- |
| Billing  
Name: | \<%=  
user.text\_field :billing\_name, :class =\> “formfield”, :size =\> “30”  
%\> |
| Billing Address:\</  
td\>  
 | \<%=  
user.text\_field :address\_line1, :class =\> “formfield”, :size =\> “30”  
%\> |
| Billing  
Address 2: | \<%=  
user.text\_field :address\_line2, :class =\> “formfield”, :size =\> “30”  
%\> |
| City, State/  
Province and Postal Code: | \<%=  
user.text\_field :city, :class =\> “formfield”, :size =\> “20” %\>  
\<%= user.text\_field :state, :class =\>  
“formfield”, :size =\> “10” %\>  
\<%= user.text\_field :zip\_code, :class =\>  
“formfield”, :size =\> “5” %\> |
| Country:\</  
td\>  
 |   
\<%= user.country\_select :country, [“United  
States”], :size =\> “10” %\> |

```
      <%= render :partial => "credit_card_details" %>
       <% hidden_field_tag "plan_type", @plan_type %>

          <table width="100%" border="0" cellpadding="0"

```

cellspacing=“0” class=“inner\_tablemrg\_clear”\>

  
&nbsp; &nbsp;\</  
td\>  
  
\<%= image\_submit\_tag “/images/buttons/button-review-  
subscription.gif”, {:alt =\> “Review Subscription”} %\>  
(link)  
  
  
  
\<% end %\>  
partial of the page

\<% @user\_cards = @user.user\_cards %\>  
\<% @user\_cards.each do |c| %\>

 \<% fields\_for "user[user\_card\_attributes]", c do |user\_card|%\> 

```
      </td>
  </tr>
  <tr>
    <td width="35%" class="left">Security Code:</td>
     <td width="65%" class="dark"><%=

```

user\_card.text\_field :short\_cc\_number, :class =\> “formfield”, :size =\>  
“20”, :index =\> 0 %\>

  

| Credit Card Details | &nbsp; |
| --- | --- |
| Credit Card Type: | \<%= user\_card.text\_field :type,:class =\> "formfield", :size =\> "20", :index =\> 0 %\> |
| Card Number: | \<%= user\_card.text\_field :cc\_number, :class =\> "formfield", :size =\> "20",:index =\> 0 %\> |
| Expiration Date: |

| Terms & Conditions |
| --- |
| Terms and conditions... |
| I hereby agree to the above Terms and Conditions |

 \<% end %\>\<% end %\>

my controller

def register\_paid\_user  
@user = current\_user  
session[:user] = params[:user]  
render :action =\> “register-purchase-review”  
end

display page

  
  
  
  
  
  
  
  

| User Information | ![Edit](https://test.ruby-forum.com/images/icons-%0Ashlm/edit.gif) Change This |
| --- | --- |
| User Details: | \< %=@user.first\_name%\>&nbsp;\<%=@user.last\_name%\>  
 \<%=@user.email%\>   

```
                      </tr>
                    </table>
        <table width="100%" border="0" cellpadding="0" 

```

cellspacing=“0”  
class=“inner\_tablemrg”\>

 |
| Billing Name  
and Address | \<img src="/images/icons-  
shlm/edit.gif" alt=“Edit” width=“11” height=“12” class=“icon\_middle” /

> Change This

 |
| --- | --- |
| Billing Details: | \<  
%=session[:user][:billing\_name]%\>  
  
\<%=session[:user][:address\_line1]%\>  
\<%=session[:user][:address\_line2]%\>  
  
\<%=session[:user][:city]%\>&nbsp;\<  
%=session[:user][:state]%\>&nbsp;\<%=session[:user][:zip\_code]%\>  
  
\<%=session[:user][:country]%\> |

  
  
  
  
  
  
  
  
  
  

| Credit Card  
Details | \<img src="/images/icons-  
shlm/edit.gif" alt=“Edit” width=“11” height=“12” class=“icon\_middle” /  
Change This |
| --- | --- |
| Card Number: | \<  
%=session[:user][:type]%\>  
  
  
  
 |
