Ruby on Rails with_option cannot call class method

Posted by Dmitri on Stack Overflow See other posts from Stack Overflow or by Dmitri
Published on 2012-09-28T09:36:02Z Indexed on 2012/09/28 9:37 UTC
Read the original article Hit count: 244

I have a problem calling class method from the with_option block with validations:

Model:

  class Model < ActiveRecord::Base
     attr_accessible :field

     with_options :if => "<not important>" do |step|
       ... bunch of validations
       step.validates :field, :inclusion => {:within => Model.field}
     end
  private
      self.field
        (1..10)
      end
  end

And it returns: undefined method `field' for #Class:0x5f394a8

self.class.field also doesn't work.

What is wrong with it ? How to fix it ?

Big big thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby