Ruby on rails 在模块中使用require——Rails
这似乎很琐碎,但却给了我极大的悲痛 我在lib文件夹中有一个模块Ruby on rails 在模块中使用require——Rails,ruby-on-rails,ruby-on-rails-3,module,require,Ruby On Rails,Ruby On Rails 3,Module,Require,这似乎很琐碎,但却给了我极大的悲痛 我在lib文件夹中有一个模块 require 'net/http' module Weather def get_response NET::HTTP.get_response(URI.parse 'someURL').body end end 控制器 class SunController < ApplicationController include Weather def show logger.debug
require 'net/http'
module Weather
def get_response
NET::HTTP.get_response(URI.parse 'someURL').body
end
end
控制器
class SunController < ApplicationController
include Weather
def show
logger.debug get_response
end
end
我得到了这个错误
uninitialized constant Weather::NET
我知道模块加载正确。我做错了什么 类是
Net::HTTP
notNet::HTTP
类是Net::HTTP
notNet::HTTP不要在自动加载路径中明确定义lib
。它将在应用程序启动时加载。不要在自动加载路径中明确定义lib
。它将在应用程序启动时加载。
uninitialized constant Weather::NET