Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何避免从引擎中设计需要身份验证的内容?_Ruby On Rails_Authentication_Devise_Rails Engines_Ruby On Rails 4.2 - Fatal编程技术网

Ruby on rails 如何避免从引擎中设计需要身份验证的内容?

Ruby on rails 如何避免从引擎中设计需要身份验证的内容?,ruby-on-rails,authentication,devise,rails-engines,ruby-on-rails-4.2,Ruby On Rails,Authentication,Devise,Rails Engines,Ruby On Rails 4.2,我在我的主要应用程序和 我已经使用“http\u basic\u authenticate\u with”构建了一个API(用于PABX),当我在操作:authenticate\u user!之前添加时,它工作得很好!,除了:[:方法\名称]到我的控制器。我这样做是因为除了:[:method\u name]将不需要Desive上的登录用户会话,我只想对这些API控制器使用基本身份验证 config/routes.rb(主应用程序) 范围模块:“api”do 作用域模块:“pabx”do 作用域“

我在我的主要应用程序和 我已经使用“http\u basic\u authenticate\u with”构建了一个API(用于PABX),当我在操作:authenticate\u user!之前添加
时,它工作得很好!,除了:[:方法\名称]
到我的控制器。我这样做是因为
除了:[:method\u name]
将不需要Desive上的登录用户会话,我只想对这些API控制器使用基本身份验证

config/routes.rb
(主应用程序)

范围模块:“api”do 作用域模块:“pabx”do 作用域“/api/pabx”do 获取“/accounts/phone_number/:phone_number”,至:“accounts#phone_number” 结束 结束 结束
控制器/api/pabx/accounts\u controller.rb
(主应用程序)

class Api::Pabx::AccountsController
当我想在引擎中执行类似于API的操作时,问题就出现了。 当我尝试访问该路由时,Desive似乎不允许在没有身份验证的情况下访问它,即使我在\u action:authenticate\u user!之前使用
!,除了:[:方法\名称]

config/routes.rb
(Myengine)

范围模块:“api”do 作用域“/api”do 获取“/accounts/phone_number/:phone_number”,至:“accounts#phone_number” 结束 结束
控制器/api/pabx/accounts\u controller.rb
(Myengine)

需要依赖关系“myengine/application\u controller”
Myengine模块
类Api::AccountsController
这是我在主应用程序中的代码

mount Myengine::Engine, at: '/myengine'
控制器/应用程序\u控制器.rb
(主应用程序)

class ApplicationController
config/routes.rb
(主应用程序)

authenticate:user do
mount Myengine::Engine,位于:'/Myengine'
结束
当我尝试在引擎中访问该方法时,终端会显示以下内容:

Started POST "/myengine/api/accounts/phone_number.json" for ::1 at 2015-09-17 21:15:31 -0300


Started GET "/users/sign_in" for ::1 at 2015-09-17 21:15:31 -0300
Processing by Devise::SessionsController#new as */*
    Rendered users/shared/_links.html.erb (6.3ms)
    Rendered users/sessions/new.html.erb within layouts/authentication (29.3ms)
    Rendered layouts/elements/_flash_messages.html.erb (2.3ms)
Completed 200 OK in 720ms (Views: 714.4ms | ActiveRecord: 0.0ms)
(如果我做错了什么,或者有人有更好的想法,请在这里分享。) (我正在使用Desive 3.5.2和Rails 4.2.0)


非常感谢您阅读我的问题。

我解决了问题,这很简单。现在,我在引擎应用程序控制器中进行身份验证,而不是通过主应用程序控制器上的路由进行身份验证

module Myengine
    class ApplicationController < ActionController::Base
        before_action :authenticate_user!
    end
end
这样我就可以在任何控制器中使用以下代码

before_action :authenticate_user!, except: [:mypublic_method]