Re: Noob question .each problem

Frederick Cheung
2010-01-04T16:22:42Z

On Jan 4, 4:10 pm, radu puspana
<radupusp...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> and this line : user.detect {|current_user| current_user =>
User.encrypt(password,current_user)}, shouldn''t be something like
> user.detect {|current_user| current_user == User.encrypt
> (password,current_user.salt)}

that''s right.
This means: iterate over the user collection, passing each element
into the block as current_user. return the first element for which the
condition in the block returns true.

> > You''ll also find your code reads more easily if variables
that contain
> > collections are pluralised (ie users = User.find :all rather than user
> > = User.find( :all))
>
> thx so much for this tip too, it doesn''t have to do anything with
the
> line user.detect {|current_user| current_user == User.encrypt
> (password, current_user)} right?

no. just a stylistic thing

Fred