Rails 3 accepts_nested_attributes_for and concurrency
I just completed RailsCasts 196 and 197, dealing with nested models in forms. Examining the generated 'name' attributes of form elements, it is quite clear that the bracketed numbers represent array positions, rather than primary key ids. E.g., in the case of:
name="survey[questions_attributes][0][answers_attributes][2][content]"
'0' indicates the first Question appearing in the form, rather than the Question with id=0 (which would be illegal in any case). Similarly, '2' indicates the third Answer, not the Answer with id=2. What if one user deletes Question 0 while another user is editing Question 1. After the delete, Question 1 will be at array po开发者_StackOverflowsition 0. Will this cause a problem? Why not just use primary keys for this?
Thanks!
I cannot reproduce this at the moment, but can you investigate the content of survey[questions_attributes][0]
?
I assume that it is a hash that contains the question's ID, in which case your scenario should work just fine. In case user A deletes question no. 0 while user B edits it should result in a question-not-found error for user B.
精彩评论