Sunday, July 20, 2008

Rails Console Tips & Tricks

Rails console have many useful tips that you may exploit as

Getting out of a block of code

If you're in an indented block of code (e.g., something that should be terminated with end) and want to escape without finishing, you can use ctrl + c to get back to the top level. The current expression will be ignored and not run.

Accessing the last return value

you can use the magic variable (_) for accessing last value
and you can then assign this value to a variable as x = _

Rollback all database changes on exit

script/console --sandbox

No comments: