rails_admin employee can only edit who is not administrator

0

Rails 5 gens rails_admin, devise, cancancan

I have a User Template : string, ..., admin_role: boolean, employee_role: boolean, user_role: boolean}

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new # guest user (not logged in)
    can :read, :all                 # allow everyone to read everything
    cannot :manage, [Gender]
    return unless user.admin_role? || user.employee_role?
    can :access, :rails_admin       # only allow admin and employee users to access Rails Admin
    can :dashboard, :all            # allow access to dashboard
    if user.admin_role?
      can :manage, :all             # allow superadmins to do anything
    elsif user.employee_role?
      can :update, [User], admin_role: false
    end
  end
end

As "can: update, [User], admin_role: false" I can "edit" only those who are not administrators, but I can not save the edit ..

What am I doing wrong?

    
asked by anonymous 09.01.2018 / 00:39

1 answer

0

I changed the can: update, [User], admin_role: false by can: manage, [User], admin_role: false

This makes the rule much more complete.

    
10.01.2018 / 16:51