my beginner''s luck has vaporized on this one. new to rails; new to ruby; but been around the block several times. my model: (Category.rb) class Category < ActiveRecord::Base self.to_xml(:only => [:id, :name], :include => [:entries] ) has_many :entries end without the to_xml mod, everything works fine. With this line in place, I get the following error: undefined method ''to_xml'' for class:0xb76bef9c Application Trace: /usr/lib/ruby/gems/activerecord-2.0.1/lib/active_record/base.rb:1459: in ''method_missing'' Please help!!!!! should I switch to using rexml? -- 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 -~----------~----~----~----~------~----~------~--~---
On Sat, May 3, 2008 at 12:35 PM, James Barnard < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > my model: (Category.rb) > > class Category < ActiveRecord::Base > self.to_xml(:only => [:id, :name], :include => [:entries] ) > has_many :entries > end > > without the to_xml mod, everything works fine. With this line in place, > I get the following error: > > undefined method ''to_xml'' for class:0xb76bef9cWith that code above, you''re trying to call the class method #to_xml on Category. That method doesn''t exist. #to_xml is an instance method inherited from ActiveRecord::Base. If you want to customize #to_xml, do something like this: class Category < ActiveRecord::Base has_many :entries def to_xml # your changes here end end Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich wrote:> On Sat, May 3, 2008 at 12:35 PM, James Barnard < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > With that code above, you''re trying to call the class method #to_xml on > Category. That method doesn''t exist. #to_xml is an instance method > inherited from ActiveRecord::Base. > > Regards, > CraigSO, I should move my code to the controller where I have access to each instance? -- 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 -~----------~----~----~----~------~----~------~--~---
On Sat, May 3, 2008 at 1:28 PM, James Barnard < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > SO, I should move my code to the controller where I have access to each > instance?Yes, your controller would do something like this: class CategoriesController < ApplicationController ... def show @category = Category.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @category.to_xml(:only => [:id, :name], :include => [:entries] ) } end end ... end Regards, Craig --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Craig Demyanovich wrote:> def show > @category = Category.find(params[:id]) > > respond_to do |format| > format.html # show.html.erb > format.xml { render :xml => @category.to_xml(:only => [:id, > :name], :include => [:entries] ) }Perfect! Thanks so much for the help! -- 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 -~----------~----~----~----~------~----~------~--~---