說我有以下型號:如何在這種情況下創建更有意義的錯誤消息?
class Information < ActiveRecord::Base
...
validates_length_of :name, :minimum=>3, :message=>"should be longer than 3 characters!"
...
我想有作爲的錯誤是:
信息應長於3個字符!(或相似)
和NOT 「信息名稱應該超過3個字符!」。
兩個可能的解決方法我已經看了:
human_attribute_name
方法(提到here):不符合我的Rails 2.3.2的工作。 :-(- 直接做
information.errors.add "","..." if information.name.length < 3
:然而,這消除由validated_length_of
方法,如特殊類標籤引發許多有用的特性(用於着色的東西紅色)
任何想法謝謝。? 。您的時間
感謝您的幫助。在我的系統上,底線顯示爲:信息名稱信息應該超過3個字符! :( – jacob 2009-07-26 08:37:55
是使用errors_for或使用我的幫手? – 2009-07-26 10:51:01
你是對的,謝謝。 – jacob 2009-07-29 13:26:32