Forum: Ruby on Rails I just can't figure it out !

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
81f1ef9f260d20fbb4ff60b3a2a6f541?d=identicon&s=25 Peter (Guest)
on 2006-02-04 18:42
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.
5ceea097a3b29cb6a5da6705926410f4?d=identicon&s=25 Gerret Apelt (Guest)
on 2006-02-04 19:06
(Received via mailing list)
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
42292bf8a0acbc98862d9306b501275d?d=identicon&s=25 Daniel Waite (rabbitcreative)
on 2006-02-04 21:14
(Received via mailing list)
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

---
81f1ef9f260d20fbb4ff60b3a2a6f541?d=identicon&s=25 Peter (Guest)
on 2006-02-05 15:15
Gerret Apelt 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!
This topic is locked and can not be replied to.