[ANN] acts_as_automatic

Acts as automatic has two purposes:

  1. provide acts_as_automatic act, which will automatically run the
    appropriate methods when conventions are adhered to (e.g. if you have
    category_id, it will assume that the model belongs_to :category). Only
    belongs_to via something_id is currently implemented.

  2. Allow the creation of associations.yml, which will hold associations
    instead of inside each individual model. There’s no need for a custom
    acts–the extension will automatically do its work if acts_as_automatic
    is installed and it finds associations.yml.

It will automatically add belongs_to to a model if it finds has_many or
has_one pointing to that model, and it supports acts_as_list.

The code is available via svn at

I will probably refactor the code to automatically support any “macros”,
because there are essentially only three types of macros:

macro_name :symbol, Hash
macro_name Hash

I will assume that each key represents a macro, and check whether
there’s nil underneath it, a Hash underneath it, or a Hash pointing to a
Hash underneath it.

Example associations.yml:

category : articles
author : articles
article : tags
author : {tags: {through: articles}}

article : attachment

article : {scope: category}
author :

Incidentally, the syntax for macro_name :symbol, Hash could have been:
author : [tags, {through: atricles}]

and I may convert to that when I refactor the code.

– Yehuda K.

Good work. I’ll have a play with it tomorrow.


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