I am working on a multiple choice question and answer application using Ruby on Rails and I have the following model.
class User < ActiveRecord::Base
has_many :questions
end
class Question < ActiveRecord::Base
belongs_to :user
has_many :answers
end
class Answer < ActiveRecord::Base
belongs_to :question
has_many :votes
end
class Vote < ActiveRecord::Base
belongs_to :user
belongs_to :answer
end
My problem is a user can choose all the answers.
How can I fix it so that it updates to the new answer?
For example, a
has 5 votes and b
3 votes.
User clicks on a
and a
increments to 6 votes, same user comes back and clicks on b
, a
decrements back to 5 votes and b
increments to 4 votes.
My first guess is that I need to add another model for example, user_choice
with user_id
and vote_id
to track the previous answer.