[英]Devise current_user not working in mountable engine
Following How To: Use devise inside a mountable engine and I can't get any of the Devise helper methods to show. 遵循方法:在可安装的引擎中使用devise ,但我无法显示任何Devise帮助器方法。
The Engine I'm using is People
. 我使用的引擎是People
。 (See my full repo ) (请参阅我的完整回购 )
module People
class ApplicationController < ActionController::Base
current_user
end
end
Returns undefined local variable or method 'current_user' for People::ApplicationController:Class
返回undefined local variable or method 'current_user' for People::ApplicationController:Class
I've tried the following 我尝试了以下
require 'devise'
at top of People::ApplicationController 在People :: ApplicationController顶部require 'devise'
require 'devise'
in host's application.rb 在主机的application.rb中require 'devise'
main_app.current_user
调用main_app.current_user
People::User.current_user
呼叫People::User.current_user
helper People::Engine.helpers
(per this SO suggestion ) 添加helper People::Engine.helpers
(根据此SO建议 ) Not sure if it's related, but when I pry
into ApplicationController and type 不确定是否相关,但是当我pry
入ApplicationController并键入时
# Pry Session
session[:foo]
=> NameError: undefined local variable or method `session' for People::ApplicationController:Class
I'm able to create Users. 我可以创建用户。
# Pry Session
People::User
=> People::User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, created_at: datetime, updated_at: datetime)
The issue here is because you're attempting to access the instance method, current_user
, in the class context and not the instance context. 这里的问题是因为您试图在类上下文而不是实例上下文中访问实例方法current_user
。 If you referred to the method inside an action in a controller, it should work. 如果您在控制器的动作中引用了该方法,则该方法应该起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.