Rails core question: building data across multiple pages

All Rails expert sites say don't keep ActiveRecords in the session. However, I have an ActiveRecord object with multiple fields that spans multiple pages. The code I'm trying to clear using hidden fields to pass data forward, which seems like a bad idea (user can interfere with one thing). What is a typical or good way to split a model's content page into multiple pages?

Note. I can save ActiveRecord to the database and then get it with the identifier that I store in the session ... the problem is that ActiveRecord has several validations that will not allow it to save without all the data. I could store the parameters themselves in a session or something ... there should be a standard way to do this ...

+3
source share
2 answers

We use the following template, which seems to work well.

  • Add an accessizard attribute called wizard_stage to the model:

    attr_accessor: wizard_stage

  • Add a hidden field: wizard_stage to the post form on each page. Set a field value that reflects what the page does, for example:

    f.hidden_field: wizard_stage,: value = > 'contact_details'

  • :

    ...: if = > lambda {| m | m.wizard_stage == 'contact_details'}

, .

, , , ( ?) .

+5

/s yaml obj.to_yaml yaml db ( ). . , . obj.to_yaml , , .

+2

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


All Articles