9

In a Rails 4 app with activeadmin gem (current master branch) I use Pundit for authorization. It works well for ressources but I don't manage to make it work for pages.

Given for example :

ActiveAdmin.register_page "Home" do
    content do
        para "some text"
    end
end

How would I authorize it for specific user ?

By reading the Pundit readme I tried with the following code but it does not work

class HomePolicy < Struct.new(:user, :home)
  def index?
    true
  end

  def show?
    true
  end
end

Any idea ?

Alex
  • 103
  • 5

1 Answers1

9

Here is an example policy that I'm using for the dashboard. I have placed it under policies/active_admin/page_policy.rb. Maybe this might be of some help

class ActiveAdmin::PagePolicy
  attr_reader :user, :record

  def initialize(user, record)
    @user = user
    @record = record
  end

  def show?
    case record.name
    when 'Dashboard'
      true
    else
      user.admin?
    end
  end
end
piton4eg
  • 1,096
  • 2
  • 10
  • 21
bsvin33t
  • 628
  • 9
  • 19
  • 1
    @Alex you have to dive into Activeadmin codebase to find things like [these](https://github.com/activeadmin/activeadmin/blob/master/spec/support/templates/policies/active_admin/page_policy.rb) – bsvin33t Apr 07 '15 at 21:10