i moved from php to rails3, and i still think it was a good decision! Anyway I have some models:
users
questions
answers
question_id
votes
user_id
answer_id
model for users:
has_many :questions
has_many :votes
model for questions:
belongs_to :user
has_many :answers, :dependent => :destroy
accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:text].blank? }, :allow_destroy => true
model for answers:
belongs_to :question
has_many :users, :through => :votes, :dependent => :destroy
has_many :votes
model for votes:
belongs_to :answer
belongs_to :user
Now my question, once a user has voted on an answer, the voting for that user and for that specific question should be closed...
I use devise and cancan for users and authorization in the rest of my project...
In my view it should look something like:
<% unless current_user.question_answered.include? question %>
and then do the script where i render the vote buttons...
In my votes model i have an answer_id and a user_id, i know the current_user.id and the current question.id so if the vote.user_id has the vote.answer_id that is in the current question.id than it shouldn't render my button making script... aarghh but how to put this to work...?
Thanks very much in advance! And best regards, Thijs