I'm having a problem where when a user fills out my evaluation form, click "Create", then click the browser's back button, make some edits, and click "Create" again, it's creating duplicate Evaluations.
What is the best way to prevent something like this happening.
Only ONE evaluation
should exist for each survey_criterion
on creation. I don't want the user to lose any data they enter after hitting the back button, filling out the form with new stuff, and clicking "Create" again.
UPDATE
routes.rb
resources :survey_criteria do
resources :groups do
resources :evaluations
end
end
survey_criterion.rb
has_many :evaluations
evaluation.rb
belongs_to :survey_criterion
belongs_to :group
There are more complicated associations, but the answer I'm looking for is more, "how does one handle it when users press the 'Back' button, modify the form, then click Create again".
I want it to update the one that was automatically created I think in this instance, and not throw an error to the user. I know I could add a validation that would error out, but I want this to be invisible to the user I think.
Thoughts?
create
action ? – m_xevaluation
along with the newsurvey_criterium
(in a nested form), or do you create both in different forms ? If i understand well what you're trying to achieve, a nested form should do the trick, because hitting the back button will get you back at the newsurvey_criterium
form, ensuring that if you hit submit again you will try to create a newsurvey_criterium
instead of a newevaluation
. – m_x