ruby-on-rails – Helper Devise:在请求环境中找不到`Warden :: Proxy`实例

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Helper Devise:在请求环境中找不到`Warden :: Proxy`实例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我尝试将Devise用于我的Rails应用程序.我可以注册登录但是当我转到我的其他页面“构建”时,我收到以下错误

Devise::MissingWarden in Home#show Devise could not find the
Warden::Proxy@H_403_6@ instance on your request environment. Make sure that
your application is loading Devise and Warden as expected and that the
Warden::Manager@H_403_6@ 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@H_403_6@ module to inject the
request.env['warden']@H_403_6@ 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

这是我的两个部分观点:

<!-- 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’)

谢谢你的帮助.

解决方法

基于此SO answer,您需要在控制器规范中包含Devise :: Test :: ControllerHelpers模块.将以下内容添加到rails_helper:
RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers,type: :controller
end

猜你在找的Ruby相关文章