Wednesday, June 29, 2011

Subtle difference between flash and

The flash variable is supposed to be used before a redirect. So it appears in the resulting page and waits for a request. So if we use it before we do anything but redirect, for instance before render, it would appear in the rendered page but is still waiting for a "redirect" request and so will appear again if you click a link.

To avoid this weird behavior we use during a render instead of flash. is supposed to be used in pages that are rendered. 

Wednesday, June 15, 2011

Ruby On Rails tutorial

Ruby on Rails tutorial by Michael Hartl is one of the few books that explains the basics of Rails ecosystem in a very simple manner. I didn't have to refer to any forum or log on to any freenode chat throughout the time I read this book. The whole ecosystem and the gears (gems) that are connected with Rails could be daunting to many. I am a Database administrator by profession and was scared when I read various online Introductions to Rails.

Firstly the installs are painful. Ruby, gem, rails etc. Here is where the author's simple no-nonsense approach starts. He relies heavily on the ecosystem for the best tool(gem) available to do the job. RVM to have a modular install for anything Rails (Ruby, gemsets etc) was excellent as I did not tinker with the underlying installs of the same software. I could uninstall(implode) RVM when I needed and reinstall gems in a much cleaner way using this amazing tool.

Secondly rspec for testing. I was curious to see why the author chose rspec over Test::Unit and found various members on forums supporting his decision due to the power and clarity of the tool. Annotate helped me in viewing the model in a descriptive form that I have been used to in the database world.

The best part of the tutorial was the 'Validating Users' part wherein we developed the login mechanism ourselves, from getting to know the various encryption algorithms available to the way we think of coding the same functionality (has_password? anyone???) was brilliant.

When I completed the book I was not only a bit conversational with the Rails world but also had developed lateral thinking in coding any functionality be it in the classical database world where I live in. For me there cannot be a better introductory book to Rails than this (believe me when I say I did try out the no.1 obvious choice that all the forums listed and was unhappy with the whole flow of the book).