0
我對我的選民has_many:through模型有一些驗證。但是,我不太清楚如何處理驗證錯誤,因爲我使用create!這是我的代碼:使用create時如何處理驗證錯誤!方法
def cast_vote_up!(user_id, direction)
voterships.create!(:issue_id => self.id, :user_id => user_id,
:direction => direction)
end
這是我的問題模型。我有問題,用戶和用戶通過聯接模式對問題進行投票。我如何處理驗證錯誤,因爲我只是使用create!通常我會做類似
if @model.save
#code
else
#other code
end
但沒有.save我不知道該怎麼做