1

我已将我的应用程序从 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)>'

请帮帮我。

4

2 回答 2

0

尝试这个:

validates_presence_of :name, :message => "Please enter the name"
于 2012-04-19T06:32:43.570 回答
0

尝试这个:

validates :name, :presence => true, :message => "Please enter the name"
于 2012-04-19T06:23:03.840 回答