Buy @ Amazon

Search This Blog

September 7, 2010

Ruby and Rails FAQ(s)

Knowing these stuff will be handy when in need and so do I post them here. If you think of (m)any stuff that should be helpful please do add them/it through comments to this post and I shall add them/it to my list of FAQs sooner.
  1. How to find the current version of Ruby installed?
    $ruby -v or  
    $ruby --version
  2. How to find the current version of RubyGem installed?
    $gem -v or  
    $gem --version
  3. How to find the current version of Rails installed?
    $rails -v or  
    $rails --version
  4. How to find environment information of RubyGems?
    $gem env
  5. How to update the current version of Rails installed?
    $sudo gem update rails
  6. How to install rails and its dependencies?
    $sudo gem install rails --include-dependencies
  7. How to find the list of plugins installed as part of gem in use?
    $gem list --local
  8. [More to come...]
Books I follow(ed) for Ruby are:
The Ruby Programming Language   Beginning Ruby: From Novice to Professional, Second Edition

Books I follow(ed) for Rails:
Simply Rails 2.0     Rails for Java Developers     Foundation Rails 2     Agile Web Development with Rails, Third Edition

Problem Updating Ruby Gem

Post the release of rubygems-update 1.3.6, I wanted to upgrade mine to it. I'm using Ubuntu and followed the steps given in Ruby Forum Link to install it. And here goes my story and how I trouble shot it...
  1. I ran the command $sudo gem update only to get the message "Nothing to update". Trouble!
  2. The above mentioned link that I was following to resolve states that I should be having an older version of RubyGems and so will have to go by the two step installation process and those being $sudo gem install rubygems-update and $update_rubygems
    Thankfully, $sudo gem install rubygems-update worked fine but then I had a problem with $update_rubygems. Trouble again!
  3. Now it is time to do this manually by going to the directory where gems is installed in the system and run the update_rubygems script manually. Where is this magic directory and how did I do it? In my case it was like running through the commands $cd /var/lib/gems/1.8/bin and $sudo ./update_rubygems
    With this I got to see the cool message "RubyGems installed the following executables: /usr/bin/gem1.8". After which I ran the $gem -v command only to see that my gem got updated to the latest and the greatest version 1.3.7. All smiles for me :)

Book(s) I read for Ruby (in that order):
The Ruby Programming Language   Beginning Ruby: From Novice to Professional, Second Edition

September 2, 2010


An avid reader I am, I encourage you to read at least a book on every technology you put to use to in your project(s). Also, it is indeed a good practice to keep reading QnA forums like in

My favourite book for SVN (subversion) is Pragmatic Guide to Subversion.
Pragmatic Guide to Subversion

So here we go with our list of FAQs in SVN. Should you like to add solutions to the problems you have had faced in this page, I encourage you to please use the comments section of this page. I shall sooner or later add it to the list of "Question and Answers" that we have for SVN, below.
  1. How to get the list of files that become a part of a particular commit in SVN repository?<br/> For every commit to svn, the repo generates a REVISION number. Using this revision number, we can fire the following command to get the list of files
    svn log -qvr <revision>
    (Also, read for more details)
  2. How to find the difference in file content between two revisions? <br/> Syntax:  svn diff -r <PREV_REVISION>:<NEW_REVISION> <FILE_NAME>
    Example: svn diff -r 3277:3278 app/models/account.rb
  3. How to get the list of files changed between two revisions? <br/> Syntax:  svn diff -r <PREV_REVISION>:<NEW_REVISION> --summarize
    Example: svn diff -r 3277:HEAD --summarize will list the files modified\added\deleted files since revision 3277 till current revision in the repo
  4. How to see the changes between two revisions, not mere list of file changes but the actual content difference between the revisions?
    Syntax:  svn diff -r <PREV_REVISION>:<NEW_REVISION>
    Example: svn diff -r 3277:3276
  5. How to see the last 'N' commit logs? 
    Syntax:  svn log -l <limit>
          (or)  svn log --limit <limit> 
    Example: svn log -l 10 will display the last 10 commits' log messages
  6. How to see the last 'N' commit logs along with the list of [added\deleted\modified] files that were committed? 
    Syntax:  svn log -vl <limit>
          (or)  svn log --verbose --limit <limit> 
    Example: svn log -vl 10 will display the last 10 commits' log messages along with the list of modified files that were committed with each such commit.
  7. How to undo a commit in svn, when a commit's revision number is known? 
    Syntax:  svn merge -r <UNDO_REVISION>:<UNDO_REVISION-1> <URL of trunk\branch where commit needs to be undone>
    Example: svn merge -r 3278:3277 will undo the 3278 commit changes in your local code base which requires to be committed with perhaps the commit message like 'Commit to undo revision 3278 changes' 
  8. How to merge a branch to a trunk (or vice-versa)? 
    Syntax:  svn merge -r <REVISION_From#>:<REVISION_To#> <URL of the source branch (or trunk) from where the changes are taken>
    Example: svn merge -r 250:HEAD will pick the changes from r250 to the last of the revision and merge all those changes to your local copy of trunk, assuming that you ran the above command from your local working directory that points to remote trunk. You may now review the local changes as a result of merge. If you are not satisfied with the changes you can revert it. If you are however happy with the changes you may commit them to the remote trunk. 
  9. [More to come...]

Additional Reading Links:

  • Read Chapter 9 - Subversion Complete Reference, at svnbook

FYI: There exists better alternatives to SVN as central repository. Some of them being Git, Mercurial etc.

Some cool books on Git, that I'm aware of are:
Pro Git     Version Control with Git: Powerful Tools and Techniques for Collaborative Software Development     Pragmatic Version Control Using Git (Pragmatic Starter Kit)     in that order. If in your experience there are better books that helped you understand Git better, please do share your experience in the comments section.

Mercurial is just another alternative to svn (or actually to Git). The one book that I'm aware of for this tool is Mercurial: The Definitive Guide (Animal Guide).