SearchNavigation |
Some Rails plugins: acts_as_catalogSubmitted by gwolf on Wed, 04/09/2008 - 17:52.
As stated yesterday, I have recently worked on some plugins for Ruby on Rails, and I do think they are usable (and useful!) for audiences larger than myself. So, today I'll present here the second such plugin. ModelsA 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). Of course, more attributes can be added to a model which acts_as_catalog - they will just be ignored by this plugin. This plugin allows you to specify your model definition as:
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:
MigrationsYou 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:
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:
TestsThis plugin provides the base functionality to include in your unit tests ensuring the catalog is properly declared. Just include ‘catalog_test_helper’ and include the CatalogTest mixin in your test classes, declare the model name, and off you go. This is, a complete unit test for you Mytable catalog model could be:
( categories: )
Reply |
Random Acidfree itemsTalks, papers and documents by categoryBlog posts by categoryCurrent weatherMexico City ![]()
Thu, 08/07/2008 - 18:47 |