Wednesday, June 13, 2007

Maintaining an object between two pages

I wanted 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 wanted 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 had a table called claims and a model that matches it. In Java Servlet Faces, I use


to pass the objects to the next page, but I was not sure how to do it on Rails. After digging around forums I found the following

Solution

There's always several ways to get the skin off the cat, but 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")

Enjoy :)

No comments: