【发布时间】:2016-01-16 21:54:36
【问题描述】:
Rails 4.2.4、Ruby 2.1.7
我在 lib/ 目录中有一个模块。
lib/BLL/user_feed.rb
module BLL
class UserFeed
def initialize
logger.debug "Class has been initialized"
end
def get_user_feed(user_id)
# logic here
return {
# object
}
end
end
end
当我尝试将其包含在我的控制器中以使用我的 user_Feed 逻辑时,
它在扔
ActionController::RoutingError(未初始化常量 UserfeedController::BLL):
错误。
我不确定出了什么问题。
class UserfeedController < ApplicationController
include BLL
before_action :authenticate_user!
def show
# some logic
end
end
【问题讨论】:
-
返回一个包含我从数据库中得到的内容的字典。
-
我认为在撰写这篇文章时有一个额外的目的。修改了一下,改正了,返回不是类级别的,是方法级别的
-
你知道 Rails 没有将
lib文件夹包含在它的加载路径中吗?您是否在您的config/application.rb中加入了config.autoload_paths << Rails.root.join('lib')之类的内容? -
是的,这就是问题所在。谢谢你的提示
标签: ruby-on-rails ruby