By: Category: Ruby on Rails,Web Development Technologies: Ruby on Rails, Database
We can add a Save as Draft function to a form, which gives the user the ability to save the information already entered so that they can complete and submit the form later.
Step 1: Add a new field like “save_as_draft” as a boolean in the table where you want to store data as a draft.
Step 2: Set default: true for field “save_as_draft” in Database.
Step 3: We can show draft and non-draft records in 2 different tables by applying
To show the draft record we can apply the condition: if table_name.save_as_a_draft == true
for show non-draft record we can apply condition: if table_name.save_as_a_draft == false
Step 4: Create a method and update the “save_as_a_draft” field after clicking on the button, in which you want to update the value of the “save_as_a_draft” field on that click from the table.
Step 5: We get 2 different tables for draft records and non-draft records from the same table in the database.
Conclusion: By using the save as a Draft concept, users can fill the form according to the data that they have at the current time for filling the form. After all, the data fill out then users can save their form-filled data as permanent.