ruby-on-rails - 无法自动加载常量 SetTitle /controllers/concerns/set_title.rb 来定义它
问题描述
我正在尝试设置页面标题。我的关注文件夹下有一个 set_title.rb 文件。
module SetTitle
extend ActiveSupport::Concern
included do
before_action:set_name
end
def set_name
if current_user
{
@set_title_name = current_user.name
}
else
{
@set_title_name = "Guest"
}
end
end
这是我的 application_controller.rb 文件
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include DeviseWhitelist
include SetTitle
end
当只有一个 DeviseWhitelist 时,我没有收到任何错误,但是当我尝试添加比它引发错误更多的问题时。
错误信息是:
无法自动加载常量 SetTitle,需要 /Users/User/Desktop/Rails/Account/app/controllers/concerns/set_title.rb 来定义它
解决方案
问题是我在 IF/ELSE 语句下使用的大括号。我删除了它们,问题就解决了。
推荐阅读
- regex - 正则表达式在替换时删除不匹配的行
- php - 仅当购物车不为空时才替换添加到购物车按钮
- react-native - 如何在 Apollo Client 中再次执行相同的查询
- excel - 使用互操作按列对工作表进行排序
- azure - 在 Azure Function App 中添加或删除主机密钥
- docker - 如何解决“!!模板:conf:2:命令中的意外未关闭操作”
- google-apps-script - 通过函数使用脚本创建文档
- json - 如何使用 slurpfile 和 jq 发送参数?
- oracle - Spark Sql Connection
- docker - 如何为 docker 使用基础镜像并从中构建自己的镜像?