CanCan - "user" parameter is nil - Rails 4

I am using Rails 4.0.1 and ruby ​​2.1.1. I am trying to integrate cancan with rails_admin. My application_controller.rblooks like this

helper_method :current_user

private

def current_user
  @current_user ||= User.find_by(email: session[:user_id]) if session[:user_id]
end 

My current_userhelper method works great with the rest of the application. My ability.rblooks like this

class Ablity
  include CanCan::Ability

   def initialize(user)
     if user
       can :access, :rails_admin
     end
   end
end

The control is not part of the if condition at all, which means that the user parameter is nil. When I try to access rails_admin, I get an exception CanCan::AccessDenied. Where am I mistaken?

Change . I do not use an authentication program.

Refresh . I replaced it cancanwith cancancanversion 1.8. Still not working

+4
1

. config/initializers/rails_admin.rb current_user_method

config.current_user_method { current_user } # refers to the current_user helper method in my case

. , .

+10

Source: https://habr.com/ru/post/1540693/


All Articles