I have a module:
module Room::Chair
def get_chair_type(user)
..
end
end
Then, I have a class with a class method ‘self.get_available_chair‘ which invoke the ‘get_chair_type‘ method in Room::Chair module:
class Store < ActiveRecord::Base
include Room::Chair
def self.get_available_chair(user)
my_chair=get_chair_type(user) # error: undefined method 'get_chair_type'
end
end
I have include Room::Chair, but I got the error undefined method ‘get_chair_type(user)’ why?
You used
include, soget_available_chairis a classmethod ofStore; and you cannot call an instance method (get_chair_type) from a classmethod.If you want
get_chair_typeto be a classmethod, useextendinstead ofinclude.