I’m looking for a way to check whether a user is logged into activeadmin from within a model. Access to a particular attribute should be denied unless the user is logged in. I was hoping for something like this, but can’t find a way to make it work:
class Object < ActiveRecord::Base
def should_show?
# find activeadmin user
if ActiveAdmin.current_admin_user?
# activeadmin user is logged in
true
else
# not logged in
false
end
end
end
Active admin uses devise for authentication.
Use devise’s method user_signed_in? for checking signed in user.
Since in active_admin user is called admin_user by default; check it with the following method
admin_user_signed_in?That is in your code replace
ActiveAdmin.current_admin_user?withadmin_user_signed_in?