0
votes

I have implemented the cancan with active_admin using below link. https://github.com/gregbell/active_admin/wiki/How-to-work-with-cancan

Just in my case the only change is below written code. app/models/ability.rb

class Ability
  include CanCan::Ability

  def initialize(user)

    user ||= AdminUser.new # guest user (not logged in)

    if user.id == 1  
      can :manage, :all      
      puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> manage all"
    else
      can :read, :all
      puts ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> read all"
    end
  end
end

For now just put condition on user.id. so when i run my application i can see my puts are on right login.

Question:

  • so if i login with user whos user.id != 1 then also i can manage all my modules in active_admin. cancan ability not working for me.

(In short my can :code isn't working in any condition)

Using rails 3.1.1, cancan 1.6.7, activeadmin 0.4.4, ruby 1.9.3

Followed commands in link correctly, double checked.

Used authorize_resource in AdminUser.

Using socery not devise, does this thing affecting the cancan?

1
"Cancan is not working well with cancan"?Chowlett
sorry didn't get you? @Chowlettchaitanya
You appear to be stating that Cancan doesn't interoperate with itself. I was questioning whether that's actually what you meant, or if you'd made a typo.Chowlett
yes cancan has issue, it doesn't working. the code written after can isn't workingchaitanya

1 Answers

1
votes

I write the following in code in every model in /admin

then my conditions in ability model start working.

  menu :if => proc{ can?(:manage, #ModelName) }     
  controller.authorize_resource 

Before posting this question i just written the above code only in admin users