Johan Van der kuijl
2008-May-13 16:13 UTC
undefined method `table_name'' for REXML::Comment:Class
Hi, I just got into polymorphic relations. It works very nice, but I ran into a strange problem that can be reproduced easily. I don''t have another workaround than to uncomment an include, but thats lame. Here it is: # My models # a generic comment class (it has a name and message) class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end # another model that has comments class Batch < ActiveRecord::Base has_many :comments, :as => :commentable end Now start a rails console and be amazed by the following: C:\rails\atlas>ruby script\console Loading development environment (Rails 2.0.1)>> include REXML=> Object>> Batch.find(:first).commentsNoMethodError: undefined method `table_name'' for REXML::Comment:Class (more error lines follow here) It looks like REXML gets in the way of my real comments here. What can I do to prevent this? regards, Johan van der Kuijl -- 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 -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-May-13 16:27 UTC
Re: undefined method `table_name'' for REXML::Comment:Class
On 13 May 2008, at 17:13, Johan Van der kuijl wrote:> > Hi, > > I just got into polymorphic relations. It works very nice, but I ran > into a strange problem that can be reproduced easily. I don''t have > another workaround than to uncomment an include, but thats lame. > Here it > is: > > # My models > > # a generic comment class (it has a name and message) > class Comment < ActiveRecord::Base > belongs_to :commentable, :polymorphic => true > end > > # another model that has comments > class Batch < ActiveRecord::Base > has_many :comments, :as => :commentable > end > > > Now start a rails console and be amazed by the following: > > C:\rails\atlas>ruby script\console > Loading development environment (Rails 2.0.1) >>> include REXML > => Object >>> Batch.find(:first).comments > NoMethodError: undefined method `table_name'' for REXML::Comment:Class > (more error lines follow here) > > It looks like REXML gets in the way of my real comments here. What > can I > do to prevent this?Don''t include REXML? What you''ve done there is make all of REXML''s constants available at the top level, including Comment. You could try requiring your comment model first. Fred> > > regards, Johan van der Kuijl > -- > 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 -~----------~----~----~----~------~----~------~--~---
Johan Van der kuijl
2008-May-14 07:48 UTC
Re: undefined method `table_name'' for REXML::Comment:Class
Frederick Cheung wrote:> On 13 May 2008, at 17:13, Johan Van der kuijl wrote: > >> >> >> It looks like REXML gets in the way of my real comments here. What >> can I >> do to prevent this? > > Don''t include REXML? What you''ve done there is make all of REXML''s > constants available at the top level, including Comment. You could try > requiring your comment model first. > > FredThx Fred, you pointed me in the right direction. I fixed it by commenting out the top level include of REXML, and adding a REXML:: prefix where neccesary, like: newdoc = REXML::Document.new() Johan -- 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 -~----------~----~----~----~------~----~------~--~---