I would like to make a before_filter on a controller with the method :current_user
And it works…
But I have an admin boolean in the user’s attributes and I would like that only the users who have this boolean at “true” use the controller.
How can I do that ?
Thank you for your answer
You can use any method that returns a boolean value as a
before_filterin rails. So in your case, just make a method likeand then call
before_filter is_admin?at the top of your controller with the actions you want to filter.Note that short-circuit evaluation of
&&ensures thatadmin?is not called oncurrent_userif it is nil.