# I just can't figure it out!

**URL:** <https://www.ruby-forum.com/t/i-just-cant-figure-it-out/101086>\
**Category:** Rails\
**Created:** [February 4, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/i-just-cant-figure-it-out/101086 "2006-02-04T18:42:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 4, 2006, 6:42pm UTC](https://www.ruby-forum.com/t/i-just-cant-figure-it-out/101086/1 "2006-02-04T18:42:03Z")

</div>

Howdy RailsWarriors,

Its probably dead easy but I don’t see it.  
Got this in my controller.

def new\_computer  
User.find(params[:id]).computers.create(:comp =\> ‘New Comp:’)  
end

Which with an .rjs template creates a div at the bottom of my list.  
This all works like a charm.  
But in the partial I load in my rjs I also have a button for ‘delete’ in  
the ‘div’  
So my question is:  
How do I get the ‘id’ of the newly created computer I created in my  
controller?  
I need that id to populate that in the partial I load in the rjs  
template.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 4, 2006, 7:06pm UTC](https://www.ruby-forum.com/t/i-just-cant-figure-it-out/101086/2 "2006-02-04T19:06:55Z")

</div>

Peter, why don’t you store the new computer in an instance variable  
that will be available to your RJS template and the partial?

cheers  
Gerret

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 4, 2006, 9:14pm UTC](https://www.ruby-forum.com/t/i-just-cant-figure-it-out/101086/3 "2006-02-04T21:14:32Z")

</div>

Not quite sure what you’re trying to do, but the database id of an  
object is available to that object after calling object.save.

e.g.

@o = Object.new params[:object]  
@o.save.id # 1

- Rabbit

* * *

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [February 5, 2006, 3:15pm UTC](https://www.ruby-forum.com/t/i-just-cant-figure-it-out/101086/4 "2006-02-05T15:15:28Z")

</div>

Gerret A. wrote:

> Peter, why don’t you store the new computer in an instance variable  
> that will be available to your RJS template and the partial?
> 
> cheers  
> Gerret

Of course !!!  
Stupid me.

Thanx both of you!
