Wednesday, December 10, 2008

Spam filtering in rails using Akismet

SPAM!!!! is a very big problem for all big applications. If you are having a site which allows users to comment on ur posts and so on then you might get affected by spamming.

Akismet is something which is helping us to avoid spamming on our sites.

There is a rails plugin available at

You can download this and configure akismet in your rails app. more information is provided in read me file of the plugin.

IF you want to see the actual implementation you can watch a screencast on

Hope this is some useful information for you.

Tuesday, December 9, 2008

Counter Cache in rails 2.1

Counter cache is really an important feature in rails 2.1 . This method is really helpful when u want to keep a count on something and avoid firing sql query every time which results in more processing times.

Here it goes

To activate this feature, you need to take two simple steps. First, add the
option :counter_cache to the belongs_to declaration in the child table.

class LineItem < counter_cache =""> true

Second, in the definition of the parent table (products in this example) you
need to add an integer column whose name is the name of the child table with
_count appended.

create_table :products, :force => true do |t|
t.column :title, :string
t.column :description, :text
# ...
t.column :line_items_count, :integer, :default => 0

Thats it .. Counter cache is enabled now.