Sunday, September 19, 2010

Using cygwin for rails!

My previous posts helped you only to install cygwin. But this time, I tried using cygwin for all rails commands.

The first step is to install rvm through your cygwin bash shell. RVM is a ruby version manager that allows you to have multiple versions of ruby installed. So, when you need to use ruby-1.8.7 or ruby-1.9.2 for certain projects you can shift from one to another.

I tried using curl command to install rvm but I was unsuccessful. So, I installed rvm as a gem. By typing the command

~ gem install rvm

And copied:

function gemdir {
if [[ -z "$1" ]] ; then
echo "gemdir expects a parameter, which should be a valid RVM Ruby selector"
else
rvm "$1"
cd $(rvm gemdir)
pwd
fi
}
in my .bash_rc file also you need to copy:

[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # This loads RVM into a shell session.

into your .bash_profile.

If you chose ruby initially when installing cygwin, the version of the ruby will be 1.8.7. However, the most current version of ruby is 1.9.2-p0. So, if you don't want to be lagging behind. In your cygwin shell, type
~ rvm install ruby-1.9.2-p0

You can see whether the rvm installed latest ruby by
~ rvm list

(for more commands of rvm try ~rvm usage)

Though you have installed latest ruby, you need to tell rvm to use that version of ruby. So,
~ rvm default 1.9.2-p0

Also you would want to use global gemset because global allows you to share gems for that version of ruby. For example, if you have two gemsets, say, projectone and projecttwo. However, they may require same gems, devise (for user login). In this case, if your global gemset has devise, then both the gemsets "projectone" and "projecttwo" can have access to that gem. So, for using global gemset
~ rvm gemset global

Similarly you can create gemsets by
~ rvm gemset create projectone

Now you would like to install gems for latest ruby. So download "rubygem 1.3.7" from in "path\to\Cygwin\home\Home\.rvm\gemsets\ruby". Also install latest rails by
~ gem install rails --pre

(In my case, the last command installed rails-3.0.0.rc2 which is not latest. So, after the rc2 was installed I tried "~ gem update rails" and it worked!)

I am using cygwin for rails commands because sometimes ruby interpreter does not allow you to install several gems however, this caveat is overcomed by cygwin. I hope this post helped you in installation.

For more information on using rvm visit beginrescueend.com, it will surely solve all your confusions if you have any regarding rvm. Have fun with rvm! ;)

Sunday, September 12, 2010

Going deep in rails!

The previous blogs were only theoretical. To learn ruby on rails in details please visit http://edgeguides.rubyonrails.org/. Follow the guide and you will have clear concept on programming in ruby on rails.