我无法做到这一点(但我可能是个白痴)。我有一个类ApplicationController
,它包含以下方法:
def logged_in?
!current_user.nil?
end
if logged_in?
load_and_authorize_resource :unless => :devise_controller?, :except => :show
end
这给了我一个错误:
未定义的方法`logged_in?' for ApplicationController:Class
这个方法是明确定义的,如何以未定义的方式返回?
答案 0 :(得分:0)
也许宣布它的最佳位置是/helpers/application_helper.rb
而不是application_controller。
此外,要验证用户是否已登录,Devise会提供以下帮助程序user_signed_in?
。
答案 1 :(得分:-1)
我认为您忘了写:
helper_method :logged_in?
在ApplicationController
中。