有什麼辦法讓模型執行一個錯誤信息,如flash[:notice]
?Rails避免重複數據庫輸入(很多屬性)
我想避免輸入相同的數據到我的數據庫兩次..
before_save :no_duplication
private
def no_duplication
if CarPrice.where(:car_id => self.car_id).where(:agent_id => self.agent_id).blank?
return true
else
return false
end
end
這段代碼複製停止,但它不發送任何錯誤消息。我該如何解決這個問題?
的可能的複製[訪問導軌閃光\ [:通知\]在一個模型(http://stackoverflow.com/questions/2701932/accessing-rails-flashnotice-in-a-model) – Pavan