我从php转移到rails3,我仍然认为这是一个很好的决定!反正我有一些型号: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
现在我的问题,一旦用户投票的答案,对于用户和特定问题的表决应该关闭......
我使用的设计,并在康康舞为用户和授权我的项目的其余部分...
在我看来,它应该是这个样子:
<% unless current_user.question_answered.include? question %>
,然后执行脚本,我呈现了投票按钮...
在我的票模型我有一个 answer_id和user_ID的,我知道 current_user.id和当前question.id 所以如果vote.user_id有vote.answer_id是在当前question.id比它不应该使我的按钮制作脚本... aarghh,但如何使这个工作...?
非常感谢! 和问候, 泰斯
谢谢!我会在今天测试它,让你知道,我做了rails 3教程,这是michael hartl的教程,在那里他们还写了一个用户登录模型...根据许多人的说法,我认为设计很好,但是制作一个自己的模型应该是更轻的,这是真的! – Thijs 2011-04-03 07:10:02
嗨,我已经做了一个用户控制器...但我想我做错了什么...?如果我仍然使用设计,我应该在哪里放置“类用户”的代码?谢谢! – Thijs 2011-04-03 08:24:55
您应该将用户模型中的代码不在控制器中。 – tommasop 2011-04-03 16:03:16