Forum: Ruby on Rails How to use Single Table Inheritance with Modules

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
9cace61bc2a5972d44d5e1a1b8c145af?d=identicon&s=25 Bram Whillock (bramski)
on 2007-05-09 22:28
(Received via mailing list)
So, I have a table...

id int
type varchar(255)
data text

Which I'm using to log some simple system events...

class Event < ActiveRecord::Base

I'd like to file quite a lot of events in here, and load them later
into a general parsing and display system for the events.  However,
what I'd really like to do is:

class Component::FooBarEvent < ActiveRecord::Base

new_event = Component::FooBarEvent.create :data => {"msg" =>"Hello
assert( new_event == Event.find_by_id( )

instead what I get is...
LoadError: Expected /home/bramski/source/trunk/config/../app/models/
events/component_events/foo_bar_event.rb to define FooBarEvent

If I look in the SQL I see...
SQL (0.000269)   INSERT INTO events ( `type`,  `data`,
`eventable1_type`, `foreign_id`) VALUES('TestEvent',  '--- \nmsg:
Hello world\n')

Now.. I should never see the above LoadError for the missing constant
as Component::FooBarEvent is already defined.  What is confusing here
is, why is rails putting in the unqualified constant for the object
(FooBarEvent) as opposed to the fully qualified constant name

Is there a way to get rails to store and load Component::FooBarEvent
as the type, rather than just FooBarEvent?
8d1e089fd6a6703f5f13dbee271aa77c?d=identicon&s=25 Yuri Leikind (Guest)
on 2007-05-10 13:13
(Received via mailing list)

How about either

renaming Component::FooBarEvent to ComponentEvents::FooBarEvent


renaming the directory component_events to component  ?


On 5/9/07, <> wrote:
> new_event = Component::FooBarEvent.create :data => {"msg" =>"Hello
> Hello world\n')
> >

Best regards,
Yuri Leikind
9cace61bc2a5972d44d5e1a1b8c145af?d=identicon&s=25 Bram Whillock (bramski)
on 2007-05-11 02:18
(Received via mailing list)
That doesn't really do anything, I still don't get ActiveRecord
storing as "type" => "ComponentEvents::FooBarEvent", I get "type" =>
"FooBarEvent", and rails is unable to locate the class
"Object::FooBarEvent" because it's "ComponentEvents::FooBarEvent".
This topic is locked and can not be replied to.