ruby-on-rails – 如何使用带有设计的rails 5中的Aplication.ren
我想实时制作我的应用程序
这是我的错误
我不知道该怎么办 请帮帮我. 解决方法
我想我找到了一个解决方案.
在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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |