This is a standard Rails code. I am using Rails 2.3.5 .
Accidentally in one of my controllers the order of formats got reversed. The altered code looks like this.
I thought order of format declaration does not matter. I was wrong.
Well I guess the order of format matters. I hope it is fixed in Rails 3.