Rails: Prevent duplicate inserts due to pressing back button and save again

前端 未结 8 1334
难免孤独
难免孤独 2020-12-09 12:13

Think about a simple Rails scaffold application with a \"new\" action containing a form to add records to a database with a \"save\" button. After the \"create\" action the

8条回答
  •  死守一世寂寞
    2020-12-09 12:55

    Your model validations will ensure things like email addresses are unique, but I think this is more about usability and experience than anything else.

    Say you are talking about an account creation form. First of all, your form submit button should say something like "Create Account", instead of just "Submit". Then depending on whether it was successful or not, show a message like either "Account successfully created" or "There were errors creating your account". If the user sees this message, they will know what happened.

    Sure you can't prevent someone from hitting the back button and hitting enter again, but you should design for the majority of use cases. If they happen to hit back, they will see the button that says "Create Account". You should probably have some other text on the page that says "Please sign up for a new account to get started".

    Just my $0.02.

提交回复
热议问题