N00b alert.. I have this code in my UserController: def add_user user = User.new if @params["user"]["password"] == @params["user"]["password2"] user.attributes = @params["user"] user.save end end How can I unset password2 since it''s not actually in the class? Or is there a better way? I guess I could assign each field individually, that how I have to do it? Also, I''m wanting to md5 the password before saving it, what class is that functionality in? Haven''t been able to find it in the docs yet. Thanks, -- Greg Donald Zend Certified Engineer http://destiney.com/
Hi! On Tue, 31 May 2005, Greg Donald wrote the following:> How can I unset password2 since it''s not actually in the class? Or is > there a better way? I guess I could assign each field individually, > that how I have to do it? > > Also, I''m wanting to md5 the password before saving it, what class is > that functionality in? Haven''t been able to find it in the docs yet.Take a look at Login Generator[1] or Salted Hash Login Generator[2]! 1: http://wiki.rubyonrails.com/rails/show/LoginGenerator 2: http://wiki.rubyonrails.com/rails/show/SaltedHashLoginGenerator bye Wolfgang
@params[''user''].delete(''password2'') Greg Donald wrote:>N00b alert.. > >I have this code in my UserController: > > def add_user > user = User.new > if @params["user"]["password"] == @params["user"]["password2"] > user.attributes = @params["user"] > user.save > end > end > >How can I unset password2 since it''s not actually in the class? Or is >there a better way? I guess I could assign each field individually, >that how I have to do it? > >Also, I''m wanting to md5 the password before saving it, what class is >that functionality in? Haven''t been able to find it in the docs yet. > >Thanks, > > > >
On 1.6.2005, at 06:58, Greg Donald wrote:> N00b alert.. > > I have this code in my UserController: > > def add_user > user = User.new > if @params["user"]["password"] == @params["user"]["password2"] > user.attributes = @params["user"] > user.save > end > end > > How can I unset password2 since it''s not actually in the class? Or is > there a better way? I guess I could assign each field individually, > that how I have to do it?If you''re using the two passwords for password confirmation, there''s already a method for it in Rails: validates_confirmation_of [1]. If you use it, you should name the second field "password_confirmation", after that the validation will kick in and you don''t have to take care of unsetting the field yourself. Of course, the main benefit is that you''ll get automatic validation for the equality of the two attributes. //jarkko [1] http://rails.rubyonrails.com/classes/ActiveRecord/Validations/ ClassMethods.html#M000620> > Also, I''m wanting to md5 the password before saving it, what class is > that functionality in? Haven''t been able to find it in the docs yet. > > Thanks, > > > -- > Greg Donald > Zend Certified Engineer > http://destiney.com/ > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Jarkko Laine http://jlaine.net http://odesign.fi _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Just to complete the response to your questions: On 5/31/05, Greg Donald <destiney-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Also, I''m wanting to md5 the password before saving it, what class is > that functionality in? Haven''t been able to find it in the docs yet.It''s in Digest, part of the standard libraries. require ''digest/md5'' user.hashed_password = Digest::MD5.digest(user.password) should do the trick. -- Chris Boone http://hypsometry.com/ : website edification http://uvlist.org/ : free classifieds for the Upper Valley
On 6/1/05, Chris Boone <hypsometry-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Also, I''m wanting to md5 the password before saving it, what class is > > that functionality in? Haven''t been able to find it in the docs yet. > > It''s in Digest, part of the standard libraries. > > require ''digest/md5'' > user.hashed_password = Digest::MD5.digest(user.password)When I add this to my user_controller.rb my add_user method is no longer found. My code looks like this: def add_user user = User.new user.attributes = @params["new_user"] user.password = Digest::MD5.digest(user.password) if user.save redirect_to :action => "index" else render end end I tried putting the require ''digest/md5'' pretty much everywhere, but it doesn''t seem to change much. What am I doing wrong? Thanks, -- Greg Donald Zend Certified Engineer http://destiney.com/