# How to maintain an object between pages?

**URL:** <https://www.ruby-forum.com/t/how-to-maintain-an-object-between-pages/92758>\
**Category:** Rails\
**Created:** [April 23, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/how-to-maintain-an-object-between-pages/92758 "2007-04-23T22:37:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dec6dc/32.png) [@Tak](https://www.ruby-forum.com/u/Tak)\
**Post date:** [April 23, 2007, 10:37pm UTC](https://www.ruby-forum.com/t/how-to-maintain-an-object-between-pages/92758/1 "2007-04-23T22:37:57Z")

</div>

Hi. I’m a newbie on Ruby on Rails (this is my first post).

I want to write a form where users can create or edit a claim. One of  
the fields is a company. Since there is an internal code for each  
registered company, I want the users to search by company name.

On the form, I plan to add a link called “Search Company”. This link  
will take the user to another form to find a company by name, and the  
matching ones will be displayed as links. If the user click on any of  
the links, the claim form page will be redisplayed with the selected  
company and the rest of the data the user has entered. Right now, I  
have a table called claims and a model that matches it.

In Java Servlet Faces, I use \<t:saveState value="#{form}"  
id=“formSaved”\>\</t:saveState\> to pass the objects to the next page,  
but I’m not sure how to do it on Rails. Any help?

Thanks.

---

<div class="post-metadata">

**Author:** ![Tak](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/dec6dc/32.png) [@Tak](https://www.ruby-forum.com/u/Tak)\
**Post date:** [April 24, 2007, 3:14am UTC](https://www.ruby-forum.com/t/how-to-maintain-an-object-between-pages/92758/2 "2007-04-24T03:14:00Z")

</div>

Tak wrote:

> Hi. I’m a newbie on Ruby on Rails (this is my first post).
> 
> I want to write a form where users can create or edit a claim. One of  
> the fields is a company. Since there is an internal code for each  
> registered company, I want the users to search by company name.
> 
> On the form, I plan to add a link called “Search Company”. This link  
> will take the user to another form to find a company by name, and the  
> matching ones will be displayed as links. If the user click on any of  
> the links, the claim form page will be redisplayed with the selected  
> company and the rest of the data the user has entered. Right now, I  
> have a table called claims and a model that matches it.
> 
> In Java Servlet Faces, I use \<t:saveState value="#{form}"  
> id=“formSaved”\>\</t:saveState\> to pass the objects to the next page,  
> but I’m not sure how to do it on Rails. Any help?
> 
> Thanks.

Well, there’s always several ways to get the skin off the cat, but I  
would just save the id of the selected company in the “session”.  
Something like this in the action that fires when they click on a  
company…

session[:selected\_company\_id] =  
Company.find\_by\_name(params[:selected\_company])  
(this assumes you are returning the selection as “selected\_company”)

hth,  
jp
