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
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
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 …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”
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