我从 php 迁移到 rails3,我仍然认为这是一个不错的决定!无论如何,我有一些模型:
users
questions
answers
question_id
votes
user_id
answer_id
用户型号:
has_many :questions
has_many :votes
问题模型:
belongs_to :user
has_many :answers, :dependent => :destroy
accepts_nested_attributes_for :answers, :reject_if => lambda { |a| a[:text].blank? }, :allow_destroy => true
答案模型:
belongs_to :question
has_many :users, :through => :votes, :dependent => :destroy
has_many :votes
投票模型:
belongs_to :answer
belongs_to :user
现在我的问题是,一旦用户对答案进行了投票,就应该关闭对该用户和该特定问题的投票...
我在我的项目的其余部分中使用设计和 cancan 作为用户和授权......
在我看来,它应该看起来像:
<% unless current_user.question_answered.include? question %>
然后在我渲染投票按钮的地方执行脚本......
在我的投票模型中,我有一个 answer_id 和一个 user_id,我知道 current_user.id 和当前 question.id 所以如果 vote.user_id 有当前 question.id 中的 vote.answer_id ,那么它不应该呈现我的按钮制作脚本... aarghh 但是如何使它工作...?
首先十分感谢!最好的问候, Thijs