我從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