2011-03-22 82 views
1

我有一个模块:未定义的方法,为什么?

module Room::Chair 

    def get_chair_type(user) 
    .. 
    end 

end 

然后,我有一个类方法 'self.get_available_chair',其调用'get_chair_type的方法在Room::Chair模块的类:

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 

我有include Room::Chair,但我得到了错误未定义的方法'get_chair_type(user)'为什么?

回答

5

您使用的是include,所以get_available_chairStore的分类方法;并且您不能从类方法调用实例方法(get_chair_type)。

如果您想要get_chair_type为类方法,请使用extend而不是include

0

因为您已在aclass Store的范围内定义了get_available_chair。它是一个类方法。它没有访问实例方法get_chair_type的权限。

相关问题