开发者

Rails 3 validate_with throws ArgumentError: wrong number of arguments

开发者 https://www.devze.com 2023-03-06 21:15 出处:网络
could anybody explain me why this code class MyValidator < ActiveModel::Validator def validate # nothing here for now

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

精彩评论

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

关注公众号