使用 Alchemy CMS 找不到设计控制器方法

Devise controller method not found using Alchemy CMS

我有一个由第三方开发的 Rails 4.1.8 应用程序;它已经将 Devise 与用户模型一起使用。我想使用 Alchemy 来管理一些主要是静态的页面,例如 "about us" 等

所以我按照说明将 Alchemy CMS 3.1.0-rc1 安装到现有应用程序中,并在初始化程序中设置 Alchemy.user_class_name。我现在将 Alchemy 安装在 /p/ 路径下,以避免与我现有的路径发生冲突。

一切似乎都运行良好,除了当我尝试在注销时查看 Alchemy 页面时,我的 application.html.erb 抛出以下错误:

undefined method `new_user_session_path' for
#<#<Class:0x007fe4c6833ee0>:0x007fe4cb5b8940>

发生这种情况是因为我的应用程序在 application.html.erb 中使用 new_user_session_path 来显示访客用户的登录名 link。在常规应用程序中,它工作正常,并且在我登录后查看炼金术页面时也工作正常。

我对 Devise 和 Alchemy 不够熟悉,无法找出问题所在。我猜这是两件事之一:

  1. 当没有登录用户时,应用程序正在创建一个 "guest" 用户(用于访问用户模型上的其他方法),而 Devise 不知道该用户,因此它不知道' t 创建 new_user_session_path 助手。
  2. 我的路由有一些问题,因为 Alchemy 是一个可安装的引擎,我的应用程序控制器中可能有一些逻辑没有被调用。

我不想 post 我的整个 routes.rb 或应用程序控制器,但这是前者的相关设计部分。

  devise_for :users, :path => "auth", :path_names => { :sign_in => 'login', :sign_out => 'logout',
    :password => 'secret', :confirmation => 'verification', :registration => 'register' },
    :controllers => {
        :registrations => "authentication",
        :passwords => "passwords",
        :omniauth_callbacks => "omniauth_callbacks",
        :sessions => "sessions"
      }

  devise_scope :user do
    # several get/post definitions here to change various urls
  end

我不认为它是#2,因为即使我为自定义路径定义了 devise_scope,例如:

devise_scope :user do
  get 'login', to: 'devise/sessions#new'
end

我遇到同样的问题:它在主应用程序和用户登录时有效,但在访客用户的 Alchemy 页面上无效。

常见rails 路由代理问题。由于 Alchemy 视图不知道您的主要应用程序路由,因此您需要使用 'main_app' 路由代理对象。

所以调用 'main_app.new_user_session_path' 应该可以解决您的问题。

阅读本 Rails 指南中有关引擎中路线的更多信息:http://guides.rubyonrails.org/engines.html#routes