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).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

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

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs