擴展模式,我有以下型號設置: 回報率:ActiveRecord的,NoMethodError在從AR
class Qa::Base < ActiveRecord::Base
self.abstract_class = true
Qa::Base.establish_connection("qa_audit_#{RAILS_ENV}")
end
class Qa::ErrorType < Qa::Base set_table_name "error_types"
# Associations has_many :errors, :class_name => 'Qa::Error' has_many :evaluations, :class_name => 'Qa::Evaluation', :through => :errors
# Validations validates_presence_of :content validates_uniqueness_of :content end
但保存時/驗證模型我不停的按以下NoMethodErrors:
NoMethodError (undefined method `add_on_blank' for #Class:0x23a3020):
例如:
e = Qa::ErrorType.first
e.valid?
產生
NoMethodError: undefined method add_on_blank' for #<Class:0x223eeb4> from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1994:in
method_missing_without_paginate'
from /opt/local/lib/ruby/gems/1.8/gems/will_paginate-2.3.14/lib/will_paginate/finder.rb:170:in method_missing' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in
send'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in method_missing_without_paginate' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2178:in
with_scope'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:207:in send' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:207:in
with_scope'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:376:in method_missing_without_paginate' from /opt/local/lib/ruby/gems/1.8/gems/will_paginate-2.3.14/lib/will_paginate/finder.rb:170:in
method_missing'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/validations.rb:599:in validates_presence_of' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:182:in
call'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:182:in evaluate_method' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:166:in
call'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in run' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in
each'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in send' from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:90:in
run'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/callbacks.rb:276:in run_callbacks' from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/validations.rb:1110:in
valid_without_callbacks?'
from /opt/local/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/callbacks.rb:315:in `valid?'
我在其他地方在同一個應用程序之前,使用相同的代碼模式,並且部分仍正常工作(所有驗證工作,因爲他們都應該)。
有人可以澄清我做錯了什麼。
解決它沒關係,問題是關聯has_many:錯誤重寫ActiveRecord :: Validations提供的'錯誤'對象,解決方案是用更具體的名稱重命名關聯 – Mukund 2011-04-27 19:25:40