# Undefined method \`table\_name' for REXML::Comment:Class

**URL:** <https://www.ruby-forum.com/t/undefined-method-table-name-for-rexml-class/137498>\
**Category:** Rails\
**Created:** [May 13, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/undefined-method-table-name-for-rexml-class/137498 "2008-05-13T18:13:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![johan-vm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@johan-vm](https://www.ruby-forum.com/u/johan-vm)\
**Post date:** [May 13, 2008, 6:13pm UTC](https://www.ruby-forum.com/t/undefined-method-table-name-for-rexml-class/137498/1 "2008-05-13T18:13:38Z")

</div>

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?

regards, Johan van der Kuijl

---

<div class="post-metadata">

**Author:** ![johan-vm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@johan-vm](https://www.ruby-forum.com/u/johan-vm)\
**Post date:** [May 13, 2008, 6:28pm UTC](https://www.ruby-forum.com/t/undefined-method-table-name-for-rexml-class/137498/2 "2008-05-13T18:28:40Z")

</div>

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.

Fred

---

<div class="post-metadata">

**Author:** ![johan-vm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c77e96/32.png) [@johan-vm](https://www.ruby-forum.com/u/johan-vm)\
**Post date:** [May 14, 2008, 9:48am UTC](https://www.ruby-forum.com/t/undefined-method-table-name-for-rexml-class/137498/3 "2008-05-14T09:48:37Z")

</div>

Frederick C. 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.
> 
> Fred

Thx 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
