Help with best-practice for Rails Model

Hello!

So, I’m fairly new to Rails and I have a question that pertains to how
to best model something that is typically addressed via inheritance.
Here’s the situation:

I need to maintain an EventLog
There are several different “types” (eight at this point) of Events
All Events have a couple of attributes in common (user_id, event_at,
note, summary, type, etc.)
Each Event has several (2-10) attributes that are unique based on “type”
summary needs to be overridden for each type, but accessible when do a
find on the superclass.
I need to expose all the functionality in an API.
The API will be used from non-Rails apps.

I would like to SIMPLY and EFFICIENTLY retrieve Events by:

ALWAYS by user_id
of any type for a given day
of a given type for a given day
of a given type for a range of days

QUESTIONS:

Should I model this using single-table inheritance?

with something like:

create_table “log_events”, :force => true do |t|
t.column “user_id”, :integer
t.column “event_at”, :datetime
t.column “note”, :text
t.column “type”, :string
t.column “type1_attr”, :integer
t.column “type2_attr”, :integer
end

class LogEvent < ActiveRecord::Base
class SubType1Event < LogEvent
class SubType2Event < LogEvent

If not, then how? (keeping it simple!)

Since event_at is a datetime, how do I best do a find by only the Date
portion?
For a Date Range?

Should I use REST or SOAP for the API?
Is one or the other better if I want to pass complex objects back and
forth?

Thanks in advance for helping me with this! I apologize about the
“Nuby” nature of these questions in advance…

Martin

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