Hi, I''m creating a new model bt class BT < ActiveRecord::Base has_many :bt_items belongs_to :user end and gather BT in a controller like this @bts = BT.find_by_product_id(@product.id) then render in a view like this <div id= "bt"> <%=render :partial => "bt/bt", :collection => @bts %> </div> and I got the following error undefined method `each_with_index'' for #<BT:0x45ed70c> Any setting I should add to the BT model to get the method work? 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 -~----------~----~----~----~------~----~------~--~---
The line: @bts = BT.find_by_product_id(@product.id) is only returning a single BT. You''re trying to render as if you had a collection of BTs, thus: @bts = BT.find_all_by_product_id(@product.id) should fix your problem. Jason On 2/15/07, Bontina Chen <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > I''m creating a new model bt > class BT < ActiveRecord::Base > > has_many :bt_items > belongs_to :user > > > end > > and gather BT in a controller like this > > @bts = BT.find_by_product_id(@product.id) > > then render in a view like this > > <div id= "bt"> > <%=render :partial => "bt/bt", :collection => @bts > %> > </div> > > > and I got the following error > > undefined method `each_with_index'' for #<BT:0x45ed70c> > > Any setting I should add to the BT model to get the method work? > > 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 -~----------~----~----~----~------~----~------~--~---
Hi Bontina, Bontina Chen wrote:> @bts = BT.find_by_product_id(@product.id) > > <%=render :partial => "bt/bt", :collection => @bts %> > > undefined method `each_with_index'' for #<BT:0x45ed70c>Just change the find to: @bts = BT.find_all_by_product_id(@product.id) Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
What are you trying to do within the ''bt/bt'' partial? What are you trying to iterate over? If you simply want access to a BT object in your partial you could try <%= render :partial => "bt/bt", :object => @bts %> Jim On Feb 15, 7:50 am, "Bill Walton" <bill.wal...-xwVYE8SWAR3R7s880joybQ@public.gmane.org> wrote:> Hi Bontina, > > Bontina Chen wrote: > > @bts = BT.find_by_product_id(@product.id) > > > <%=render :partial => "bt/bt", :collection => @bts %> > > > undefined method `each_with_index'' for #<BT:0x45ed70c> > > Just change the find to: > > @bts = BT.find_all_by_product_id(@product.id) > > Best regards, > Bill--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---