Login controller additions

Jonas Montonen
Thu, 10 Mar 2005 15:35:40 -0000

I have added roles and roles_users table and updated the model so that
my users can have multiple roles.
("Admin" role does always have id = 1).

I have added these methods to my application controller.

  helper_method :is_admin?
  helper_method :is_user?

  def is_admin?
      if @session[''user'']
        @session[''user''].roles.find(1)
      else
        false
      end
  end

  def is_user?
    !@session[''user''].nil?
  end


The problem is that if a user does not have the role "admin" (id=1)
the
@session[''user''].roles.find(1) statment fails with error
"unable to find
role with id = 1".

How can I do this another way..... I know it must be simple... but I''m
really a Rails/Ruby newbie ;)

Regards
// JoNtE