简体   繁体   中英

How to hide some pages from users and only show it to Admin ?

I have installed the Activ Admin gem but not sure it will be of any help. I have some pages which I want to hide from being seen by anonymous and some from logged in users too. How can I do it ?

I am sure there must be ACL gems in RoR but I am not sure which is the standard and preferred way to do it ? any help ? Thanks

I'm not familiar with Active Admin but, assuming you already have a way of determining if a user is logged in (and you have a way to address the current_user ), you could simply do the following:

in your controller (or in your sessionshelper for example)

def admin_users_only
  unless current_user.admin? redirect_to "wherever you want to redirect to"
end

in the same controller

before_filter :admin_users_only, only: [:index, :or, :any, :other]

(of course your user model needs an admin attribute)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM