开发者

Rails 3 validate_with throws ArgumentError: wrong number of arguments

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 开发者_StackOverflow社区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.


Your #validate method needs to accept one parameter (the model it's validating).

http://api.rubyonrails.org/classes/ActiveModel/Validator.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜