Topic: Scaffolding newbie question

Hi everyone,

sorry, if this is a really stupid question, but there

Re: Scaffolding newbie question

According to the rails API, The new method let your @user inherit attributes from the User model (in other words, from your users table). This is to make sens to for e.g. @user.id or @user.login

And in the create method: @user = User.new(params[:user]) is creating the object @user by recopying which is an OOP concept (creating a user and filling its attributes from params[:user]).

(i'm not sure about all what i said !)

Re: Scaffolding newbie question

Its rails magic smile

User.new creates a new User object, but does not save it. It is used because of page refresh. If you do not use User.new then if you would enter something wrong and submit it, you would get an error for validation and your previous entry like name, e-mail etc. would not be there. User.new(params[:user]) saves the user object.

Last edited by Eric_Jardas (2007-04-15 12:58:21)

Re: Scaffolding newbie question

User.new(params[:user]) saves the user object.

Except you mean User.create(params[:user]) saves the user object.

BrewControl.com - Brewery and Brewpub management powered by RoR

Re: Scaffolding newbie question

Oh yeah..my mistake...actually what i wanted to write was:
@user = User.new(params[:user])
@user.save