So, I have a table…
events
id int
type varchar(255)
data text
Which I’m using to log some simple system events…
class Event < ActiveRecord::Base
end
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
end
new_event = Component::FooBarEvent.create :data => {“msg” =>“Hello
world”}
assert( new_event == Event.find_by_id(new_event.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
(Component::FooBarEvent).
Is there a way to get rails to store and load Component::FooBarEvent
as the type, rather than just FooBarEvent?