This project is archived and is in readonly mode.

#4876 ✓resolved
Luke van der Hoeven

No method '_validate_callbacks'

Reported by Luke van der Hoeven | June 16th, 2010 @ 09:33 PM

I have the following code

class AnswerValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    record.errors[attribute] << (options[:message] || "question not answered") if value.nil? and !record.errors[attribute].include?(options[:message] || "question not answered")
  end

end

class Answer
  include ActiveModel::Validations

  attr_accessor :id

  def to_param
    (id = self.id) ? id.to_s : nil
  end

   def to_key
     persisted? ? nil : [id]
   end  

  #answer will always be new
  def persisted?
    false
  end

  def set_attributes(values)
    values.each do |k,v|
      self.send "#{k}=".to_sym, v
    end
  end


  def initialize(questions=nil)
    # create accessor methods
    if questions
      questions.each do |q|        
        name = q["sqt_name"].gsub(/(-|\s)/, "_").downcase.to_sym

        class_eval {
          attr_accessor name
          validates name, :answer => true if q['sqt_required_fl']
        }
      end    
    end
  end  
end

Everytime initialize gets run (via @answer = Answer.new(@survey.survey_questions))

I get the following error:
NoMethodError (undefined method _validate_callbacks' for #<Class:Answer>):<br/> /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/core_ext/class/inheritable_attributes.rb:172:in_validate_callbacks' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:580:in _update_validate_superclass_callbacks' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:435:insend' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:435:in __update_callbacks' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:474:inset_callback' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations.rb:128:in validate' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations/with.rb:82:invalidates_with' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations/with.rb:70:in each' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations/with.rb:70:invalidates_with' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations/validates.rb:88:in validates' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations/validates.rb:81:ineach' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activemodel-3.0.0.beta4/lib/active_model/validations/validates.rb:81:in validates' /code/survey-app/app/models/answer.rb:46:ininitialize' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/core_ext/kernel/singleton_class.rb:11:in class_eval' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta4/lib/active_support/core_ext/kernel/singleton_class.rb:11:inclass_eval' /code/survey-app/app/models/answer.rb:44:in initialize' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_collection.rb:408:inmethod_missing' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_proxy.rb:214:in method_missing' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_proxy.rb:214:ineach' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_proxy.rb:214:in send' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_proxy.rb:214:inmethod_missing' /home/server/.rvm/gems/ruby-1.8.7-p249/gems/activerecord-3.0.0.beta4/lib/active_record/associations/association_collection.rb:408:in method_missing' /code/survey-app/app/models/answer.rb:41:ininitialize' /code/survey-app/app/controllers/answers_controller.rb:15:in new' /code/survey-app/app/controllers/answers_controller.rb:15:innew' ...

This worked fine in 3.0.0.beta. Tried looking through the changelogs but can't really tell if anything changed here.

Using Rails 3.0.0.beta4 + Ruby 1.8.7 (tried 1.9.1/2 as well).

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

Pages