我已将我的应用程序从Rails 2.3.5迁移到Rails 3。
我在模型中有验证,如
validates :name, :presence => {:message => "Please enter the name"}
我收到错误。该错误指向我添加验证的行。错误日志如下
activemodel (3.2.2) lib/active_model/validations/with.rb:85:in `block in validates_with'
activemodel (3.2.2) lib/active_model/validations/with.rb:83:in `each'
activemodel (3.2.2) lib/active_model/validations/with.rb:83:in `validates_with'
activemodel (3.2.2) lib/active_model/validations/validates.rb:99:in `block in validates'
activemodel (3.2.2) lib/active_model/validations/validates.rb:90:in `each'
activemodel (3.2.2) lib/active_model/validations/validates.rb:90:in `validates'
app/models/business.rb:19:in `<class:Business>'
app/models/business.rb:1:in `<top (required)>'
请帮帮我。
答案 0 :(得分:0)
试试这个:
validates :name, :presence => true, :message => "Please enter the name"
答案 1 :(得分:0)
试试这个:
validates_presence_of :name, :message => "Please enter the name"