【问题标题】:Unable to autoload constant SetTitle /controllers/concerns/set_title.rb to define it无法自动加载常量 SetTitle /controllers/concerns/set_title.rb 来定义它
【发布时间】:2018-12-10 13:56:25
【问题描述】:

我正在尝试设置页面标题。我的关注文件夹下有一个 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 来定义它

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-5.2


    【解决方案1】:

    问题是我在 IF/ELSE 语句下使用的大括号。 我删除了它们,问题就解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-28
      • 2019-04-10
      • 1970-01-01
      • 2019-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多