2017-01-28 4 views
5

Я пытаюсь использовать приложение Devise for my 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 %> 

После отладки я понял, что проблема возникает из этой строки в моем «шоу» контроллере: 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