Re: Noob question .each problem

radu puspana
2010-01-04T16:53:36Z

On Jan 4, 6:22 pm, Frederick Cheung
<frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:
> 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.

Sry for bothering you agan but shouldn''t it be :
 user.detect {|current_user| current_user.hashed_password
=User.encrypt(password,current_user.salt)} reather than user.detect {|
current_user| current_user== User.encrypt
(password,current_user.salt)} ??.
== means a condition if i recall correctly.
because the string that comes out of  User.encrypt
(password,current_user.salt)} should be compared with something in the
current_user, namely hashed_password,  not the object refered by the
variable current_user, right?
>
> > > 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
 thx again for the trick:)
> Fred

much much appreciate it Fred,
regards,