Forum: Ruby on Rails Re: Global Method Declaration?

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.
A43dfa24838887d5ea9ac1f2820317c4?d=identicon&s=25 Sean Cribbs (Guest)
on 2006-03-30 18:16
(Received via mailing list)
Since session variables are visible in the view, why not set one:

session[:is_admin]

One of your before filters or your login routine could set this the
first time, then you can access it from both places.  This would also
simplify your is_admin before filter:

def is_admin
  session[:is_admin]
end

Cheers,

Sean Cribbs
Web Services - KCKCC

>>> bljohnson@gmail.com 3/30/2006 10:03 AM >>>

Is there a place where I can put a method that can be accessed in both
views and controllers?

Here's the situation, maybe someone can suggest a better way to go about
this:

I created my own custom login system with email verification and user
roles (basically, I tinkered around with SaltedHashLoginGenerator
until I finally gave up and wrote my own).  One role, of course, is an
admin role.  Users with this designation can add headline articles,
new employee bios, etc.

All methods in a controller may or may not need the admin role so I
cant use a before_filter in all of them.  So I created an is_admin
method and put it in the application controller.  Works great.
Problem is, there are times when I need to do an is_admin check inside
a view.

So where can I place is_admin so both the view and controller can call
it?  Is there a better way of doing this?

Thanks,

- Brent
This topic is locked and can not be replied to.