这是我的错误
ActionView::Template::Error (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 theWarden::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 theDevise::Test::ControllerHelpers
module to inject therequest.env['warden']
object for you.)
1: -if user_signed_in?
2: .ui.popup.computer{id:”post#{post.id}user#{post.user.id}”,style:”padding:0px”}
3: .ui.card
4: .image
我不知道该怎么办
请帮帮我.
解决方法
在ApplicationController中定义renderer_with_signed_in_user类方法.
class ApplicationController < ActionController::Base ... def self.renderer_with_signed_in_user(user) ActionController::Renderer::RACK_KEY_TRANSLATION['warden'] ||= 'warden' proxy = Warden::Proxy.new({},Warden::Manager.new({})).tap { |i| i.set_user(user,scope: :user,store: false,run_callbacks: false) } renderer.new('warden' => proxy) end ... end
然后你可以从Rails应用程序的其他部分渲染,如下所示:
renderer = ApplicationController.renderer_with_signed_in_user(user) renderer.render template: 'notifications/show',layout: false,locals: { foo: 'bar' }
感谢Stefan Wienert的article
原文地址:https://www.jb51.cc/ruby/267895.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。