drpepper
drpepper

Reputation: 165

Saving data in rails session to use in form on next request

Let's say I have a table called positions (as in job positions). On the position show page I display all the detail about the job - awesome. At the bottom I need the prospective applicant to input their professional license # before continuing onto the next page which is the actual applicant creation form. I also need to take that license # and have it populate that field on the applicant form (again on the proceeding page).

I realize there are a couple ways to do this. Possibly the more popular option would be to store that value in the session. I am curious how to do this in the simplest manner?

My idea:

  1. Create a table specifically for license #'s.
  2. Add a small form on the position show page to create license # (with validation)
  3. Store newly created license in session - not sure what to put in which controller?
  4. On applicant creation form populate from session the license #.

This would assume applicants only have one license.

Thoughts?

Appreciate the help!

Upvotes: 3

Views: 11150

Answers (3)

Jerome
Jerome

Reputation: 1

The hidden field is safer for data persistence. However is not not then coded in the HTML output? That can be a great data security issue.

This is a trade-off to be considered.

Upvotes: 0

marcgg
marcgg

Reputation: 66445

Don't store this in the session! Pass that as an hidden field.

Let's say the user starts the form, then open the form again in a new window or something... then the session variable would be shared between the two forms. Other problems would occur if the cookie gets removed (session expire, user clear cache...)

This is not good. The best way is using a POST variable. GET works as well but messes up the URL

Upvotes: 3

Eric
Eric

Reputation: 766

Seems like a good idea. As for #3, for whatever controller is called in the transition from 2 -> 4, that would be the controller where you store the session, as such:

session[:license_number] = your_license_number_information

From there, it can be called the same way (session[:license_number]) to get it.

Upvotes: 3

Related Questions