Rails 3 validate_with 抛出 ArgumentError:参数数量错误
谁能解释一下为什么这段代码
class MyValidator < ActiveModel::Validator
def validate
# nothing here for now
end
end
class MyModel < ActiveRecord::Base
validates_with MyValidator
end
会抛出这个异常(当我尝试创建模型对象时):
ArgumentError: wrong number of arguments (1 for 0)
/data/rubydev/kalpana/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:314:in `validate'
/data/rubydev/kalpana/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:314:in `send'
我使用了 这个教程。它应该有效。
could anybody explain me why this code
class MyValidator < ActiveModel::Validator
def validate
# nothing here for now
end
end
class MyModel < ActiveRecord::Base
validates_with MyValidator
end
throws this exception (when I try to create a model object):
ArgumentError: wrong number of arguments (1 for 0)
/data/rubydev/kalpana/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:314:in `validate'
/data/rubydev/kalpana/gems/activesupport-3.0.3/lib/active_support/callbacks.rb:314:in `send'
I used the tutorial for this one. It should work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
#validate
方法需要接受一个参数(正在验证的模型)。http://api.rubyonrails.org/classes/ActiveModel/Validator.html
Your
#validate
method needs to accept one parameter (the model it's validating).http://api.rubyonrails.org/classes/ActiveModel/Validator.html