2017-01-28 19 views
5

Tôi cố gắng sử dụng Devise cho ứng dụng Rails của mình. Tôi có thể đăng ký và đăng nhập nhưng khi tôi đi đến trang khác của tôi "xây dựng" Tôi nhận được lỗi sau:Helper Devise: không thể tìm thấy cá thể `Warden :: Proxy` trên môi trường yêu cầu

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.

Đây là bộ điều khiển của tôi:

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 

Đây REA hai quang cảnh một phần của tôi:

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

Sau khi gỡ lỗi, tôi đã phát hiện ra rằng sự cố xuất phát từ dòng này trong bộ điều khiển "hiển thị" của tôi: template = HomeController.render ('layout/_template')

Cảm ơn sự giúp đỡ của bạn.

+0

Điều này có xảy ra khi bạn chạy ứng dụng cục bộ hoặc khi bạn chạy bộ thử nghiệm của mình không? –

Trả lời

9

Dựa trên SO answer này, bạn cần bao gồm mô-đun Devise::Test::ControllerHelpers trong thông số bộ điều khiển của mình. Thêm thông tin sau vào rails_helper của bạn:

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

Cảm ơn bạn, rất tiếc là nó không hoạt động. – AlphaNico

+0

Sau khi gỡ lỗi, tôi đã phát hiện ra rằng sự cố đến từ dòng này trong bộ điều khiển "hiển thị" của tôi: template = HomeController.render ('layout/_template') – AlphaNico

Các vấn đề liên quan