acts_as_catalog is a very simple plugin providing the common infrastructure for probably the most frequent auxiliar table ever: The catalog (a small table with only an ID and a name). It provides extensions for models, migrations and tests.
Models
A catalog is defined as a table with only a +name+ column of +string+ type, and with a unique index on it (this means, does not allow for duplicate values). This plugin allows you to specify your model definition as:
def Mytable < ActiveRecord::Base
acts_as_catalog
belongs_to :some_other_table
end
A catalog is often accessed to populate i.e. drop-down selection or radio boxes, passing what is called +collections+ in Rails-speak. You will often want collections to be sorted by ID or by name, thus:
collection = Mytable.collection_by_id
another_col = Mytable.collection_by_name
Migrations
You can specify all the catalogs you need to create for a specific migration with a single instruction from inside your self.up method, by giving a list of catalog table names to create_catalogs:
def self.up
create_catalogs :countries, :states
...
end
Likewise, you can destroy the created catalogs in a single command. The drop_catalogs method will usually be the last thing you call in self.down:
def self.up
...
drop_catalogs :states, :countries
end
What's New in This Release:
· Added the collection-handling class methods (collection_by_id, collection_by_name)
Product's homepage