2017-01-28 75 views
5

我嘗試使用Devise for Rails應用程序。我可以註冊和登錄,但是當我去我的其他頁面「構建」我收到以下錯誤:Helper Devise:根據請求環境找不到`Warden :: Proxy`實例

Devise::MissingWarden in Home#show Devise could not find the Warden::Proxy instance on your request environment. Make sure that your application is loading Devise and Warden as expected and that the Warden::Manager middleware is present in your middleware stack. If you are seeing this on one of your tests, ensure that your tests are either executing the Rails middleware stack or that your tests are using the Devise::Test::ControllerHelpers module to inject the request.env['warden'] object for you.

這裏是我的控制器:

class ApplicationController < ActionController::Base 
    protect_from_forgery with: :exception 

    private 
    # Overwriting the sign_out redirect path method 
    def after_sign_out_path_for(resource_or_scope) 
    build_path 
    end 
end 

這裏REA我的兩個部分觀點:

<!-- views/devise/menu/_login_items.html.erb --> 
<% if user_signed_in? %> 
    <li> 
    <%= link_to('Logout', destroy_user_session_path, :method => :delete) %> 
    </li> 
<% else %> 
    <li> 
    <%= link_to('Login', new_user_session_path) %> 
    </li> 
<% end %> 

<!-- views/devise/menu/_registration_items.html.erb --> 
<% if user_signed_in? %> 
    <li> 
    <%= link_to('Edit registration', edit_user_registration_path) %> 
    </li> 
<% else %> 
    <li> 
    <%= link_to('Register', new_user_registration_path) %> 
    </li> 
<% end %> 

調試後,我發現問題來自我的「show」控制器中的這一行:template = HomeController.render('layouts/_template')

感謝您的幫助。

+0

這是在您本地運行應用程序或運行測試套件時發生的嗎? –

回答

9

基於此SO answer您需要在您的控制器規格中包含Devise::Test::ControllerHelpers模塊。將以下內容添加到您的rails_helper中:

RSpec.configure do |config| 
    config.include Devise::Test::ControllerHelpers, type: :controller 
end 
+0

謝謝,不幸的是它不起作用。 – AlphaNico

+0

調試後,我發現問題來自我的「show」控制器中的這一行:template = HomeController.render('layouts/_template') – AlphaNico

相關問題