This project is archived and is in readonly mode.
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:in
send'
/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:in
set_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:in
validates_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:in
validates_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:in
each'
/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:in
initialize'
/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:in
class_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: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: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:in
each'
/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:in
method_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:in
initialize'
/code/survey-app/app/controllers/answers_controller.rb:15:in
new'
/code/survey-app/app/controllers/answers_controller.rb:15:in
new'
...
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
-
Luke van der Hoeven June 16th, 2010 @ 10:37 PM
- Title changed from No method ' to No method '_validate_callbacks'
-
Luke van der Hoeven June 16th, 2010 @ 10:38 PM
Also, ran a few other setups, I can get around this using 3.0.0.beta under Ruby 1.9.1. All 1.8.7 configurations (including 3.0.0.beta) appear to break.
-
José Valim June 22nd, 2010 @ 04:32 PM
Could you add a failing test against Rails ActiveModel test suite? Thanks!
-
Neeraj Singh June 22nd, 2010 @ 09:43 PM
@Luke Can you try with the latest code. When I try to recreate your problem on my machine I get following error.
ArgumentError: Attribute names must be symbols
which is referring to this block
class_eval { attr_accessor name validates name, :answer => true }
-
Neeraj Singh July 16th, 2010 @ 04:05 AM
- State changed from new to incomplete
- Importance changed from to Low
@Luke not sure what I did last time.
This time I not able to proceed because you did not show survey_question model.
Also I am not sure what is the intent of having class_eval.
-
Luke van der Hoeven July 16th, 2010 @ 04:42 PM
Turns out it had to do with class reloading underneath the dynamically generated survey code. Had to enable class caching in dev mode. This can be considered resolved, thanks.
-
Neeraj Singh July 16th, 2010 @ 04:43 PM
- State changed from incomplete to resolved
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>