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