简体   繁体   中英

Undefined method logged_in? Ruby on Rails

I can't make head or tail of this (but I'm probably being an idiot). I have a class ApplicationController that contains the following method:

def logged_in?
  !current_user.nil?
end

if logged_in?
  load_and_authorize_resource :unless => :devise_controller?, :except => :show
end

This gives me an error:

undefined method `logged_in?' for ApplicationController:Class

This method is clearly defined, how is it coming back as undefined?

Maybe the best place to declare it is in /helpers/application_helper.rb instead of application_controller.

Also, to verify if a user is signed in, Devise provides the following helper user_signed_in? .

Source: https://github.com/plataformatec/devise

I think you forgot to write:

helper_method :logged_in?

in ApplicationController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM