New user.presentation

Hi,

I’m creating an RoR application right now and i’ve got the following
question:

An user has one presentation.

So i’ve got an user table and in that table is an field
fkPresentationID. Now i want to create an new user and at the same
moment an new presentation for that user. I thought it would work with
something like this, but it didn’t work.

@user = User.new(params[:user])
@user.presentation.new(params[:presentation])
if @user.save
flash[:notice] = ‘OK.’
redirect_to :action => ‘list’
else
render :action => new
end

Can anyone tell me what i’m doing wrong?

Thanks in advance

Daan wrote:

Hi,

I’m creating an RoR application right now and i’ve got the following
question:

An user has one presentation.

So i’ve got an user table and in that table is an field
fkPresentationID. Now i want to create an new user and at the same
moment an new presentation for that user. I thought it would work with
something like this, but it didn’t work.

@user = User.new(params[:user])
@user.presentation.new(params[:presentation])
if @user.save
flash[:notice] = ‘OK.’
redirect_to :action => ‘list’
else
render :action => new
end

Can anyone tell me what i’m doing wrong?

Thanks in advance

I think this should be @user.presentation = Presentation.new


Agnieszka F.

On 3/18/06, Daan [email protected] wrote:

Hi,

I’m creating an RoR application right now and i’ve got the following
question:

An user has one presentation.

So i’ve got an user table and in that table is an field
fkPresentationID.

Hi Daan,
Not fully awake yet (still working on my first pot of coffee :slight_smile: …but I
did
want to point one thing out…
You do know that the convention for this field is typically
presentation_id
? If you need this field name, make sure you have this in your
Presentation
model:
belongs_to :user, :foreign_key => “fkPresentationID”

HTH,
Dean

Daan wrote:

Hi,

I’m creating an RoR application right now and i’ve got the following
question:

An user has one presentation.

So i’ve got an user table and in that table is an field
fkPresentationID. Now i want to create an new user and at the same
moment an new presentation for that user. I thought it would work with
something like this, but it didn’t work.

@user = User.new(params[:user])
@user.presentation.new(params[:presentation])
if @user.save
flash[:notice] = ‘OK.’
redirect_to :action => ‘list’
else
render :action => new
end

Can anyone tell me what i’m doing wrong?

Thanks in advance
@user needs to be saved before a presentation can be attched, becasue
user needs to have a id for the presentation to recognize it.

@user = User.new(params[:user])
if @user.save
@user.presentation.create(params[:presentation])
flash[:notice] = ‘OK.’
redirect_to :action => ‘list’
else
render :action => new
end

joey__
http://www.feedreed.com

Thanks all,

I works finaly :slight_smile:

i’m using the following code right now:

@user = User.new(params[:user])
@presentation = Presentation.new(params[:presentation])
@user.valid?
@presentation.valid?
if @presentation.valid? and @user.valid?
@presentation.save
@user.presentation = @presentation
@user.lastlogin = Time.now
@user.save
flash[:notice] = ‘Ok’
redirect_to :action => ‘list’
else
render :action => ‘new’
end