Ruby on rails 未定义的方法,尽管包含我的模块
我有这个模块:Ruby on rails 未定义的方法,尽管包含我的模块,ruby-on-rails,Ruby On Rails,我有这个模块: module Moody def foo 'bar' end end 但在控制器中: class MyController include Moody # this works. Including Moodasdasd causes a failure def index puts foo #=> expect 'bar' undefined local variable or method `foo' raise
module Moody
def foo
'bar'
end
end
但在控制器中:
class MyController
include Moody # this works. Including Moodasdasd causes a failure
def index
puts foo #=> expect 'bar' undefined local variable or method `foo' raised
end
end
我得到一个未定义的局部变量或方法错误
我应该如何在操作中包含模块的方法?我猜该模块没有包含在应用程序命名空间中 如果不知道模块文件的位置,我无法确定 尝试在应用程序名称空间中包含文件路径,看看这是否有帮助
就像下面的要点一样:我复制了这个,它对我来说很好。(没有错误)