2017-01-28 7 views
5

Próbuję użyć Devise dla mojej aplikacji Rails. mogę się zarejestrować i zalogować, ale kiedy idę do mojej drugiej stronie „budować” pojawia się następujący błąd:Helper Devise: nie można znaleźć instancji `Warden :: Proxy` na żądanie środowisko

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.

Oto mój kontroler:

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 

Tutaj Rea moje dwie częściowe widoki:

<!-- 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 %> 

i

<!-- 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 %> 

Po debugowaniu, zorientowałem się, że problem pochodzi z tej linii w moim kontrolerze "show": template = HomeController.render ("layouts/_template")

Dzięki za pomoc.

+0

Czy dzieje się to po uruchomieniu aplikacji na miejscu lub po uruchomieniu pakietu testowego? –

Odpowiedz

9

Na podstawie tego SO answer należy dołączyć moduł Devise::Test::ControllerHelpers do specyfikacji kontrolera. Dodaj do swojego routera:

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

Dziękuję, niestety to nie działa. – AlphaNico

+0

Po debugowaniu zorientowałem się, że problem pochodzi z tego wiersza kontrolera "show": template = HomeController.render ("layouts/_template") – AlphaNico

Powiązane problemy