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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With