How do I avoid concurrency and keep the data integrity if one user
submit a
form before the other?
My issue is that the last user to submit the person/_form.rb will get
all
chosen cards, same the cards that first user chose and I want to
prohibit
that.
# person.rb
class Person < ActiveRecord::Base
has_many :cards
end
# card.rb
class Card < ActiveRecord::Base
belongs_to :person
scope :not_assigned_to_a_person, -> { Card.where(person_id: nil) }
end
# create_cards.rb
create_table :cards do |column|
column.references :person, index: true
end
# person/_form.rb
= f.input :card_ids,
collection: Card.not_assigned_to_a_person,
label_method: :name, value_method: :id,
input_html: { multiple: true }
StackOverflow:
http://stackoverflow.com/questions/25216219/how-do-i-avoid-concurrency-belongs-to-and-has-many-association
Ricardo do Valle