加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 如何使用带有设计的rails 5中的Aplication.ren

发布时间:2020-12-16 21:10:57 所属栏目:百科 来源:网络整理
导读:我想实时制作我的应用程序 这是我的错误 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 the Warden::
我想实时制作我的应用程序

这是我的错误

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 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.)
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读