Re: user.save not saving?

Michael Koziarski
Sat, 28 May 2005 22:23:26 -0000

On 5/29/05, Ben Jackson
<ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org>
wrote:
> I have a controller definition to complete a form and send a
> confirmation email:

Here are a few tips.

> >       def complete
> >               if @session[''user'']
> >                       @user =
User.find(@session[''user''][''id''])
> >                       if @user.update_attributes(@params[:user])
> >                               flash[''notice''] =
''Thank you.''
> >                       end
> >
> >               else
> >                       @user = User.new(@params[:user])
> >                       @user.pass = @user.random_pass

You could make this happen in the model itself

> >                                       @user.login =
@params["user"]["login"]
> >                       if @user.save
> >                               flash[''notice''] =
''Thank you.''
> >                       end

Validation could be failing,  either try using @user.save! which will
throw an exception on failure,  or stick in an else block of
render_text @user.errors.inspect

> >               end
> >               Mailer::deliver_complete( User.find(@user.id) , @survey)
> >       end
>
> If the user has been created and is already logged in, it updates fine.
> However
>
> >                       if @user.save
> >                               flash[''notice''] =
''Thank you.''
> >                       end
>
> Is not being executed. Adding new users through the admin system is
> functional. What could be going wrong? Thanks,
> ___________________
> Ben Jackson
> Diretor de Desenvolvimento
>
> ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org
> http://www.incomumdesign.com
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cheers

Koz