Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does this 'validate' method raise an ArgumentError?
    primarykey
    data
    text
    <p>Folks,</p> <p>I can't get <code>validates_with</code> in my (helloworld-y) rails app to work. Read through "callbacks and validators" section of the original <a href="http://guides.rubyonrails.org/active_record_validations_callbacks.html#validates_with" rel="nofollow">RoR guides site</a> and searched stackoverflow, found nothing.</p> <p>Here's the stripped-down version of code I got after removing everything that can fail.</p> <pre><code>class BareBonesValidator &lt; ActiveModel::Validator def validate # irrelevant logic. whatever i put here raises the same error - even no logic at all end end class Unvalidable &lt; ActiveRecord::Base validates_with BareBonesValidator end </code></pre> <p>Looks like textbook example, right? They have the very similar snippet on <a href="http://guides.rubyonrails.org/active_record_validations_callbacks.html#validates_with" rel="nofollow">RoR guides</a>. Then we go to the <code>rails console</code> and get an ArgumentError while validating new record:</p> <pre><code>ruby-1.9.2-p180 :022 &gt; o = Unvalidable.new =&gt; #&lt;Unvalidable id: nil, name: nil, created_at: nil, updated_at: nil&gt; ruby-1.9.2-p180 :023 &gt; o.save ArgumentError: wrong number of arguments (1 for 0) from /Users/ujn/src/yes/app/models/unvalidable.rb:3:in `validate' from /Users/ujn/.rvm/gems/ruby-1.9.2-p180@wimmie/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:315:in `_callback_before_43' </code></pre> <p>I know I'm missing something, but what?</p> <p>(NB: To avoid putting <code>BareBonesValidator</code> into separate file I left it atop <code>model/unvalidable.rb</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload