Smorgasbord - Politics, Lisp, Rails, Fencing, etc.

My musings on assortment of things ranging from politics, computer technology and programming to sports.

Wednesday, March 22, 2006


On this day:

Some good news

I am leaving for Amritsar today, to participate in the National fencing competition. Since, I don’t have much of fencing experience behind me, the expectations are not very high, but I will give it my best shot and aim for the best possible result.

Thursday, March 09, 2006


On this day:

Rails User Engine - Adding permissions

A while back, there was discussion on the engines mailing list on how to add permissions for different roles in the database for the user engine.

My preferred way of doing this is using migrations. I will illustrate it here using an example, say we have a controller about with actions ["terms", "privacy", "faq", "about"] and we want to give permissions to both Guest and User roles to have access to this.

So, to write a migration for this, fire up a shell and type:


ruby script\generate migration AddPermissionsData



This will create a new migration file in the `db\migrate' folder:



class AddPermissionsData < ActiveRecord::Migration
def self.up
end

def self.down
end
end



Now, to add permissions modify the above file, and add the following code:



class AddPermissionsData < ActiveRecord::Migration
def self.up
guest_role = Role.find_by_name("Guest")
user_role = Role.find_by_name("User")
controller_actions = {:about => ["terms", "privacy",
"faq", "about"] }
controller_actions.each do |controller,actions|
for action in actions
permission = Permission.find_by_controller_and_action(
controller.to_s,action)
if permission
permission.roles << guest_role
permission.roles << user_role
end
end
end
end

def self.down
guest_role = Role.find_by_name("Guest")
user_role = Role.find_by_name("User")
controller_actions = {:about => ["terms", "privacy",
"faq", "about"]}
controller_actions.each do |controller,actions|
for action in actions
permission = Permission.find_by_controller_and_action(
controller.to_s,action)
if permission
permission.roles.delete guest_role
permission.roles.delete user_role
end
end
end
end
end




The code in self.down should remove whatever was added in self.up.

Important: Before running the above migration, don't forget to run rake sync_permissions.

If you know of a better approach of doing the above then please post it as a comment.

Monday, March 06, 2006


On this day:

India in Nuclear Club

The article We Are (Aren't) Safer With India in the Nuclear Club in New York Times discusses the recently signed Indo-US Nuclear Deal. Being an Indian, the initial reaction would be to disparage the article, but some of the points raised in article are worth pondering.
In particular:

the deal could make the world more dangerous: Even if India is a responsible player, the deal could touch off a regional race to produce more bomb fuel. In that case, more of that fuel would be floating around — perhaps to tempt terrorists.

On a more positive note:

India shows restraint and Mr. Bush's gamble pays off, other nations that defiantly built their own weapons may gradually be drawn back into a new club whose membership rules are still being written.

Friday, March 03, 2006


On this day:

Protests and Violence - Psyche

In Lucknow, 4 people were killed as anti-George Bush protests turned violent. In the past also many people died, and property worth millions were destroyed during violent protests in Nigeria, Pakistan etc., against the cartoons.

Many people must be wondering why such protests needlessly turn violent and hurt the local civilians and property. Rarely ever is the offending party anywhere near the scene of protest, so what end can be achieved by needless violence and self-destruction.

Well the truth is (at least in India, and I can imagine quite likely in Pakistan, Nigeria and other developing nations) the people who participate in these rallies are rarely genuinely concerned about the issue at stake. Even if occasionally they do sympathize with the issue, nevertheless they participate in these rallies only for monetary benefits.

These protests are generally organized by local politicians or pseudo-religious leaders and they pay the participants wages for taking part in the rallies. The poor people who go to these protests are most often well aware that there will be some violence but still the lure of easy money is strong enough to overcome the fear. The leaders then hire some goons and miscreants to cause violence, because generally the success of the protest is gaged by the amount of violence and destruction it causes, besides it also helps in getting coverage in local and international news.