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. -- Posted via http://www.ruby-forum.com/.
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 On 2/4/06, Peter <macgebruiker@hotmail.com> wrote:> 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. > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 --- On 2/4/06, Gerret Apelt <gerret.apelt@gmail.com> 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 > > > On 2/4/06, Peter <macgebruiker@hotmail.com> wrote: > > 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. > > > > -- > > Posted via http://www.ruby-forum.com/. > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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 > GerretOf course !!! Stupid me. Thanx both of you! -- Posted via http://www.ruby-forum.com/.