Forum: Ruby on Rails Constructing current_user.recipes for administrators?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2c2f3ce7125411ff78a1d3e902aa2a4d?d=identicon&s=25 Bob Sanders (adistarmid)
on 2008-11-26 10:14
I'm using the restful_authentication's current_user. So to find a user's
recipes, I use:

current_user.recipes

I want the admin (I have an "admin" column in the users table) to view
all recipes. I'm doing this right now, but think its too verbose:

@recipes = current_user.admin? ? Recipe.all : current_uesr.recipes

Is there a more efficient way to have the admin view all recipes (and
non-admin only to view their own recipes) instead of doing the above?
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick (Guest)
on 2008-11-27 07:52
(Received via mailing list)
You might think of an index all that is accessible only to admin.

before_filter :check_admin_role, :only => [:index]

Rick

On Nov 25, 11:14 pm, Bob Sanders <rails-mailing-l...@andreas-s.net>
This topic is locked and can not be replied to.