0
我有一個聯繫表單,並希望根據什麼失敗顯示個人消息。我想使用Flash消息。所以從我讀到目前爲止,我可以創建自定義方法(或我認爲它只是覆蓋了一個到位?)自定義驗證Rails模型
因此,舉例來說,我想驗證名稱字段的存在
Class Message
attr_accessor :name
validates :name, :presence => true
def validate
if self.name < 0
errors.add(:name, "Name cannot be blank")
end
end
end
在我的控制,我通常使用一個通用的消息
flash.now.alert = "Please Ensure all Fields are filled in"
有沒有一種方法來調用驗證失敗的特定消息?
感謝
我該如何在閃光警報中顯示消息? – Richlewis
@Richlewis查看這個[application](https://github.com/RailsApps/rails3-bootstrap-devise-cancan)作爲例子。因此,如果您有任何疑問,您可以獲得完整的申請。 –