ruby on rails - how to make devise admin see everything? -


i have scoped current_user

eg:

@integrations = current_user.integrations.all 

for trouble shooting, want admin see users. have boolean on user model admin: true

to around admin seeing everything, keep doing this:

def index      if current_user.admin?         @integrations = integration.all.includes(:user)         @reports = report.all     else         @integrations = current_user.integrations          @reports = current_user.reports     end end 

i feel there easier way... suggestions?

thanks!

you maybe abstract admin check protected/private method in user controller:

def is_admin   current_user.admin? end 

and @ top of controller, place before action catch whatever methods want:

class userscontroller < applicationcontroller   before_action :is_admin, only: [:index, :show]   # rest of code end 

or

class userscontroller < applicationcontroller   before_action :is_admin, except: [:destroy]   # rest of code end 

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

javascript - Which segment of a polyline was clicked? -

c# - Avoiding duplicate methods for Task and Task<T> -