Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 未定义的方法,尽管包含我的模块_Ruby On Rails - Fatal编程技术网

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
我得到一个未定义的局部变量或方法错误


我应该如何在操作中包含模块的方法?

我猜该模块没有包含在应用程序命名空间中

如果不知道模块文件的位置,我无法确定

尝试在应用程序名称空间中包含文件路径,看看这是否有帮助


就像下面的要点一样:

我复制了这个,它对我来说很好。(没有错误)