Reputation: 486
I don't really have any examples, but I have forms that create new records in my ActiveRecord database that do not really have any unique attributes other than their given ID. It has come to my attention that Users are submitting their form, but realized they mistyped something, so they have been pressing the browser's back button and resubmitting the same content, which causes duplication of that record.
I want to prevent this from happening, there is no need to post code, I would just like some suggestions.
Thanks!
Upvotes: 0
Views: 592
Reputation: 10009
In the record's Model, add a uniqueness validation as detailed in this Rails Guide. You can apply a scope on that validation, so that the uniqueness is determined using multiple record attributes.
Alternatively, if you really don't want to mark these records as unique, add an easy way for the user to update their submission to the post record creation page. i.e. they add a new record, the ability to edit that record immediately pops up in their view so that, rather than hitting back and creating a new record, they update the one they just made.
Upvotes: 1