Forum: Ruby on Rails Calling class methods from included module

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.
1e782845563c051556143a36ee9cf365?d=identicon&s=25 Rasmus Nielsen (rasmus)
on 2009-01-04 17:13

I have these two ActiveRecord models: UserEvent and CoordinateEvent.

The models are extended with the module MapEvent. MapEvent includes some
class methods and some instance methods.

Now, I want both models to use ActiveRecord's serialize

My MapEvent looks something like the following. I simply can't figure
where to put "serialize :column_name":

module MapEvent
  def self.included(base)

  def a_method

  module ClassMethods
    def another_method

How do I call the serialize method from the above context?

An extra question:
Also, it suddenly hit me, that instead of a module I could write
MapEvent as a class that inherits from ActiveRecord instead of a module
- and then let UserEvent and CoordinateEvent inherit from MapEvent?
Would you recommend this? Generally speaking, when should you use
mixins/module and when you use inheritance?

Hope my questions are clear. Thanks in advance!
1e782845563c051556143a36ee9cf365?d=identicon&s=25 Rasmus Nielsen (rasmus)
on 2009-01-04 17:26
Well - I think I now can answer both of my questions myself. In case
anyone is curious here is what I've learned:

In order to call the serialize method that the two models inherited from
AR write this:
module MapEvent
  def self.included(base)
    base.serialize :command

This makes sense as serialize is just an instance method of the models.

And regarding the module/inheritance question I found an answer reading
these article (including the comments):

Modules should generally speaking be used when you just want to add
methods to your concrete classes. If you want to add new class or
instance variables use "normal" inheritance.
This topic is locked and can not be replied to.