Re: Login controller additions

Jarkko Laine
Thu, 10 Mar 2005 15:50:07 -0000

On 10.3.2005, at 17:35, Jonas Montonen wrote:
>
> 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".

This is because find assumes that the record with given id exists, i.e.
that user knows there should be such row in the db. Therefore not
finding that row is an exceptional state. find_all is a method that
doesn''t assume any number of rows returned.

However, in your case @session[''user''].roles is an array so
you can do
something like this:
@session[''user''].roles.collect{ |role| role.id }.include?(1)

//jarkko

--
Jarkko Laine
http://jlaine.net
http://odesign.fi


_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org