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

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

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

The canvas has been tainted by cross-origin data in chrome only -