Friday, January 29, 2010

Awesome Taxonomy module for categorise content in drupal

Taxonomy is pretty cool for creating categories in drupal. You can create multiple categories and sub categories for each node type. These categories are applied to the partucalar nodes as you mention. So the same category set can be set to multiple content types and also each content type have multiple categories lists. See all about taxonomy at http://groups.drupal.org/taxonomy

A small Tip

A small tip to call methods dynamically using Ruby's send method.

["foo", "bar"].each do |method|
MyClass.send(method)
end

The above code is same as calling MyClass.foo and MyClass.bar.

Make your rails application DRY with constants

Constants help with consistency, they easily allow you to keep your code DRY.
One of the ways I utitilise constants is to standardise the date formatting I use across an app.
For example, in environment.rb I will create a module to contain my date format constants:

module Dates
DATE_FORMAT = "%d% %b %Y"
DATE_TIME_FORMAT = "#{DATE_FORMAT} %H:%M"
end

The module just groups them nicely together. To use the constants I will write the following:

@object.created_at.strftime(Dates::DATE_FORMAT)
@object.created_at.strftime(Dates::DATE_TIME_FORMAT)

Remember you will need to restart your server after making any changes to environment.rb