0

We use Formtastic and built add_fields / remove_fields for one to many association models based on this railscasts. Now we are encountering a duplicate entries problem. Say, after we create a new project, and then edit this project with 3 tasks loaded, if I add one more task when editing, this new added task is duplicated in database.

We also use update_attributes to check validation and AJAX to submit the form and run the process in the background job in sidekiq.

And I found this link, but I'm using rails 3.2. Not sure what I can do for this case...

Has anyone met this problem before? I'm now trying to post my codes here.(too complicated to simplify posting here hehe)

UPDATE So after a long investigation of this problem, we found the double entry is caused by submitting AJAX twice.

Community
  • 1
  • 1
user2775888
  • 39
  • 10
  • `validates_uniqueness_of` in your Model might help: http://apidock.com/rails/ActiveRecord/Validations/ClassMethods/validates_uniqueness_of – Kelsey Hannan Apr 08 '15 at 06:14
  • @Kelseydh we also tried this similar solution, add index to multiple columns but it doesn't solve the original problem. but this is a good idea to detect double entries. – user2775888 Apr 23 '15 at 02:10

1 Answers1

0

As answered in the other StackOverflow question you mentioned, you have to send the id attribute for each task while sending the parameters via ajax.

akshay_kashain
  • 700
  • 5
  • 12