Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access devise current_admin_user in AcitveAdmin form definition

I need to display some form fields in ActiveAdmin form only to specific users. But when I try to check user status with this code:

ActiveAdmin.register Store do
  # ...
  form do |f|
    f.inputs "Basic" do
      if current_admin_user.super_admin?
        f.input :admin_user
      end
     # ...
     end
  end
end

I get

undefined local variable or method `current_admin_user' for #<ActiveAdmin::DSL:0xdb8e798>

CanCan methods also don't work in the ActiveAdmin form definition.

Generally my question is: how can I manage admin interface display, based on current user type? Particularly, how can I get current devise user object from within ActiveAdmin definitions?

like image 529
Catalyst Avatar asked Jun 22 '26 06:06

Catalyst


1 Answers

It is a matter of scope. You could try accessing the helper method using the f.template object like so:

ActiveAdmin.register Store do
  # ...
  form do |f|
    f.inputs "Basic" do
      if f.template.current_admin_user.super_admin?
        f.input :admin_user
      end
     # ...
     end
  end
end

Good luck.

like image 158
Sjors Branderhorst Avatar answered Jun 27 '26 11:06

Sjors Branderhorst



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!