tomas
1
Hi,
I want to exten ActiveRecord::Base with own methods:
class Stock < ActiveRecord::Base
def compare_own
…
end
end
But call Stock.compare_own fails:
NoMethodError: undefined method compare_own' for Calendar:Class /var/lib/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1129:in
method_missing’
But why?
I want to use only ActiveRecord from RoR, I hope this isn’t a problem.
Best regards,
Tomas
tomas
2
Tomas F. wrote:
class Stock < ActiveRecord::Base
def compare_own
…
end
end
But call Stock.compare_own fails:
NoMethodError: undefined method compare_own' for Calendar:Class /var/lib/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:1129:in
method_missing’
You’ve defined an instance method but you’re trying to call it as a
class method.
Given your current code, you have to have an instance of Stock before
you can call your method:
s = Stock.new # or s = Stock.find(:first), etc.
s.compare_own
If you really mean it to be a class method, then you can define it like
this:
def self.compare_own
…
end
Does this help?
Jeff
tomas
3
On Aug 11, 2006, at 7:09 PM, Tomas F. wrote:
base.rb:1129:in
`method_missing’
You defined an instance method, but called a class method.
Dave