Saving data in a rails session for use in the form at the next request

Say I have a table called positions (like in workplaces). On the show position page, I show all the details about the job - awesome. Below, I need a future applicant to enter their professional license # before moving on to the next page, which is the actual form for creating the applicant. I also need to take this license # and fill out this field in the applicant form (again on the continue page).

I understand that there are several ways to do this. Perhaps a more popular option would be to keep this value in the session. I am curious how to do this in the easiest way?

My idea:

  • Create a table specifically for license #.
  • Add a small form to the line item’s page to create license # (with validation)
  • Save the newly created license in the session - do not know what to add to the controller?
  • Fill out license # in the form for creating an applicant from the session.

This assumes that applicants have only one license.

Thoughts?

Appreciate the help!

+3
source share
3 answers

Do not store this in a session! Pass this as a hidden field.

Let's say a user launches a form, then reopens the form in a new window or something like that ... then the session variable will be split between the two forms. Other problems may occur if the cookie is deleted (session expires, user cache ...)

. - POST. GET , URL

+3

. №3, , 2 → 4, , , :

session[:license_number] = your_license_number_information

(session [: license_number]), .

+3

A hidden field is safer for saving data. However, is the HTML output encoded as a result? This can be a big data security issue.

This is a compromise to consider.

0
source

Source: https://habr.com/ru/post/1717770/


All Articles