# New user.presentation

**URL:** <https://www.ruby-forum.com/t/new-user-presentation/55239>\
**Category:** Rails\
**Created:** [March 18, 2006, 12:22pm UTC](https://www.ruby-forum.com/t/new-user-presentation/55239 "2006-03-18T12:22:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daan](https://www.ruby-forum.com/u/Daan)\
**Post date:** [March 18, 2006, 12:22pm UTC](https://www.ruby-forum.com/t/new-user-presentation/55239/1 "2006-03-18T12:22:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daan](https://www.ruby-forum.com/u/Daan)\
**Post date:** [March 18, 2006, 1:38pm UTC](https://www.ruby-forum.com/t/new-user-presentation/55239/2 "2006-03-18T13:38:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Daan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daan](https://www.ruby-forum.com/u/Daan)\
**Post date:** [March 18, 2006, 2:53pm UTC](https://www.ruby-forum.com/t/new-user-presentation/55239/3 "2006-03-18T14:53:48Z")

</div>

On 3/18/06, Daan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂 …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

---

<div class="post-metadata">

**Author:** ![Daan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daan](https://www.ruby-forum.com/u/Daan)\
**Post date:** [March 18, 2006, 3:29pm UTC](https://www.ruby-forum.com/t/new-user-presentation/55239/4 "2006-03-18T15:29:39Z")

</div>

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](http://www.feedreed.com)

---

<div class="post-metadata">

**Author:** ![Daan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@Daan](https://www.ruby-forum.com/u/Daan)\
**Post date:** [March 18, 2006, 3:38pm UTC](https://www.ruby-forum.com/t/new-user-presentation/55239/5 "2006-03-18T15:38:29Z")

</div>

Thanks all,

I works finaly 🙂

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
