I have the following code in my controller: def edit_password_process @user = User.find(@params[''user''][''id'']) @user.password = @params[''user''][''password''] if @user.save flash[:notice] = "Your password has been updated." else flash[:error] = "We encounted an error while trying to modify your password." end redirect_to :action => "index", :id => @user.id end The problem with this is that it does not verify that password and password_confirmation are equal. Is there a sweet rails way of doing this? :-)
John Kopanas wrote:> I have the following code in my controller: > > def edit_password_process > @user = User.find(@params[''user''][''id'']) > @user.password = @params[''user''][''password''] > if @user.save > flash[:notice] = "Your password has been updated." > else > flash[:error] = "We encounted an error while trying to > modify your password." > end > redirect_to :action => "index", :id => @user.id > end > > > The problem with this is that it does not verify that password and > password_confirmation are equal. Is there a sweet rails way of doing > this? :-)Just add a password_confirmation field to the form and add the validation rule to the model: validates_confirmation_of :password rgds, Dema -- http://dema.ruby.com.br - Rails development from a .NET perspective
Yeah... that is all there. On creation the validation works great it is just when I update it like below it does not consider the password_confirmation field that I have in the form. Any other possibilities? On 3-Jun-05, at 11:43 AM, Demetrius Nunes wrote:> John Kopanas wrote: > >> I have the following code in my controller: >> def edit_password_process >> @user = User.find(@params[''user''][''id'']) >> @user.password = @params[''user''][''password''] >> if @user.save >> flash[:notice] = "Your password has been updated." >> else >> flash[:error] = "We encounted an error while trying >> to modify your password." >> end >> redirect_to :action => "index", :id => @user.id >> end >> The problem with this is that it does not verify that password >> and password_confirmation are equal. Is there a sweet rails way >> of doing this? :-) >> > > Just add a password_confirmation field to the form and add the > validation rule to the model: > > validates_confirmation_of :password > > rgds, > Dema > -- > http://dema.ruby.com.br - Rails development from a .NET perspective > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> writes:> Yeah... that is all there. On creation the validation works great it > is just when I update it like below it does not consider the > password_confirmation field that I have in the form. > > Any other possibilities?does your validation limit the confirmation of the password on :create? -- doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org
Nope... it is right next to all the other validations that are working. On 3-Jun-05, at 1:17 PM, Doug Alcorn wrote:> John Kopanas <john.kopanas-O1KSuMybMhqBUy7/sJONFg@public.gmane.org> writes: > > >> Yeah... that is all there. On creation the validation works great it >> is just when I update it like below it does not consider the >> password_confirmation field that I have in the form. >> >> Any other possibilities? >> > > does your validation limit the confirmation of the password on > :create? > -- > doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >