The simplest solution would be to modify the create action, which should work like this pseudocode:
def create # ... if evaluation_exists? update_evaluation(params[:evaluation]) else create_evaluation(params[:evaluation]) end # ... end
As for your question , how to handle it, when users click the "Back" button, change the form and then click "Create again" , then I use some random token (short line), placed as a hidden field in the form.
When a create request arrives, I check to see if this token is saved in the session. If this is not the case, I create an object and add this token to the list of used ones. If the token is already present in the session, I know that the user has just resubmitted the form, and I can act accordingly. I usually ask him if another object should be created. In a session, I usually store no more than 3-5 tokens.
It looks like this (yes, this is just an illustration):
def create token = params[:token] session[:tokens] ||= [] if session[:tokens].include? token render_the_form_again( "You have already created the object. Want another?" ) else create_the_object session[:tokens] << token end
source share