@u=User.find(session[:user_id]) @friends=@u.friends #puts @friends #render :partial => "friend", :collection => @friends @friendpicks =@u.friends.collect{|x| x.products.sort_by{|x| x.id}.reverse.first(10)} --------------------------so far no problem--------------------------------------- @friendpicks.id (irb):21: warning: Object#id will be deprecated; use Object#object_id => 29883400 ----------------------------------------------------------------------------------- I''ve checked that @friendpicks is an array with #<Product:0x449263c> #<Product:0x4492678> #<Product:0x44926b4> #<Product:0x448cb88> but somehow they are all treated as objects and all the methods for product becomes strangers. Anyone knows why I''m getting this? Any help is highly appreciated. Abon -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Nugent
2007-Jan-18 15:20 UTC
Re: Expecting a definrd model id, but returning object id
The answer is that @friendpicks is an array and that you are getting the object id of the array, not the model ids of the contents of the @friendpicks array. You probablly want something more like @friendpicks.each do |pick| pick.id end On 1/18/07, Bontina Chen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > @u=User.find(session[:user_id]) > @friends=@u.friends > #puts @friends > #render :partial => "friend", :collection => @friends > > @friendpicks =@u.friends.collect{|x| x.products.sort_by{|x| > x.id}.reverse.first(10)} > > --------------------------so far no > problem--------------------------------------- > > @friendpicks.id > (irb):21: warning: Object#id will be deprecated; use Object#object_id > => 29883400 > > ----------------------------------------------------------------------------------- > I''ve checked that @friendpicks is an array with > #<Product:0x449263c> > #<Product:0x4492678> > #<Product:0x44926b4> > #<Product:0x448cb88> > > but somehow they are all treated as objects and all the methods for > product becomes strangers. > > Anyone knows why I''m getting this? > Any help is highly appreciated. > > > Abon > > -- > Posted via http://www.ruby-forum.com/. > > > >-- -Dan Nugent --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bontina Chen
2007-Jan-19 01:52 UTC
Re: Expecting a definrd model id, but returning object id
Daniel Nugent wrote:> The answer is that @friendpicks is an array and that you are getting > the object id of the array, not the model ids of the contents of the > @friendpicks array. > > You probablly want something more like > > @friendpicks.each do |pick| > pick.id > end > > On 1/18/07, Bontina Chen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> --------------------------so far no >> #<Product:0x44926b4> >> >> -- >> Posted via http://www.ruby-forum.com/. >> >> > >> > > > -- > -Dan NugentIt still returns the object id. Anyway I can turn it to a product? Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Nugent
2007-Jan-19 03:01 UTC
Re: Expecting a definrd model id, but returning object id
Hmm.. sorry, I think I missed a level of nesting. @friendpicks = @u.friends.collect do |friend| friend.products.sort_by do |product| product.id end.reverse.first(10) end So, if I''ve reinterpreted this right, you''re getting a list of lists of 10 products each, sorted by their id, then reversed. So to access each of the lists you want @friendpicks.each. Then to access each of the picks lists you want @friendpicks.each{|pick| pick.each} Which will ultimately get you: @friendpicks.each do |picks| picks.each do |pick| pick.id end end Now, if you''ve got your console open, you can check the class of each of the objects by using the class method, and if you want to inspect them, try either p or inspect. On 1/18/07, Bontina Chen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Daniel Nugent wrote: > > The answer is that @friendpicks is an array and that you are getting > > the object id of the array, not the model ids of the contents of the > > @friendpicks array. > > > > You probablly want something more like > > > > @friendpicks.each do |pick| > > pick.id > > end > > > > On 1/18/07, Bontina Chen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> --------------------------so far no > >> #<Product:0x44926b4> > >> > >> -- > >> Posted via http://www.ruby-forum.com/. > >> > >> > > >> > > > > > > -- > > -Dan Nugent > > It still returns the object id. > Anyway I can turn it to a product? > Thanks > > -- > Posted via http://www.ruby-forum.com/. > > > >-- -Dan Nugent --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bontina Chen
2007-Jan-20 04:27 UTC
Re: Expecting a definrd model id, but returning object id
I am not sure I''m getting [[p p][p p][p p p]] or [p p p p p p]. I would like a [[p p][p p][p p p]] transforming to a [p p p p p p]. Thanks -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Daniel Nugent
2007-Jan-20 05:25 UTC
Re: Expecting a definrd model id, but returning object id
Okey doke. I thought you just wanted to iterate through the elements. In that case, just add .flatten to the end of that method chain, like so: @friendpicks =@u.friends.collect{|x| x.products.sort_by{|x| x.id}.reverse.first(10)}.flatten Now, @friendpicks is an array of product objects. Sorry I misunderstood! On 1/19/07, Bontina Chen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > > I am not sure I''m getting [[p p][p p][p p p]] > or [p p p p p p]. > I would like a [[p p][p p][p p p]] transforming to a [p p p p p p]. > Thanks > > -- > Posted via http://www.ruby-forum.com/. > > > >-- -Dan Nugent --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bontina Chen
2007-Jan-21 02:34 UTC
Re: Expecting a definrd model id, but returning object id
Thanks for all your help. I''m get an array of products now. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---