I am new to rails and trying to learn now so hopefully someone can help.
I have 3 models for User, Opinion and Vote with one-to-many relationships. Each user has_many :opinions
and has_many :votes
. Each opinion has_many :votes
and belongs_to :user
. Each vote belongs_to user
and belongs_to opinion
. Votes table has columns for :decision (boolean), :opinion_id and :user_id. Opinions table only has :content column.
My use case is that a user adds an opinion and then other users can either agree or disagree with it when viewing each opinion (show view).
In Opinion show view I want to have two submit buttons with "Agree" and "Disagree". When a user submits a vote I need to create this vote (true or false) and update both user_id and opinion_id fields of the votes table. I managed to do it for each parent individually but not both for the same vote. Any help would be much appreciated.