Tag: Rails

Ruby on Rails envy part 3 – Getting started with Rails 3 on Snow Leopard

This is the third post about getting started on Ruby on Rails. Now I’m on my MacBook, which I ust upgraded from 10.5 to 10.6.6. Since Ruby is already installed on the Mac, I did not need to use the Bitnami virtual machine I used in the previous articles.

Installing Rails

Here’s how I got ROR running on my MacBook:

  • Install Git here
  • Install RVM from a Terminal like this:
    [code lang=”bash”]
    bash < <( curl )
  • add this to ~/.profile:
    [code lang=”bash”]
    [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    Then logout the terminal and log back in.

  • Install Rails 1.9.2 like so:
    [bash] rvm install 1.9.2 [/bash]
  • Set 1.9.2 as default like so: [bash]rvm –default 1.9.2[/bash]
  • Install Rails 3: [bash]gem install rails[/bash]
  • Install sqlite 3 [bash] gem install sqlite3-ruby[/bash]
  • Check versions with [bash] rails -v[/bash] and [bash] ruby -v [/bash] and see if they’re OK
  • The cool thing about install Rails like this is that everything is installed in my home folder, and you can completely run your apps from you home folder. So you don’t need elevated rights to install or run an application.

    Get the party started

    Create a new Rails project:
    $ rails new Weblog
    $ cd Weblog
    $ rails generate scaffold Story title:string posted_on:date storytext:text
    $ rake db:migrate
    $ rails s

    Now, browse to http://localhost:3000/stories to take a look at your app.

    At least you know everything is running well and I am at the same point I was here. Next time (maybe tomorrow), let’s check out what actually happened.

Ruby On Rails Envy – how to set up a ROR environment (with BitNami)

From the moment I read about ScottGu sitting in a plane and setting the outline for ASP.NET MVC, I couldn’t help thinking: “This is a serious case of Ruby On Rails Envy.” I know, the MVC pattern is very old indeed, but I thought it is more than coincidental that, with the success of ROR, Microsoft comes up with an alternative. Oh well. Just my humble opinion.

I was writing webapplications with the Ruby on Railsframework back then (I think it is 2008) but as ASP.NET MVC matured I switched. Because the companies I work for do have a Windows environment ready for me, so practically I had to. And I never looked back at ROR. Which is a shame, because Ruby.Is.Beatiful.

So let’s get our hands dirty and get started with Ruby On Rails!

But wait. What? Where? How?

Setting up the Rails environment

If you are on a Mac or on Linux it’s relatively easy to set up a Rails environment. If you’re on Windows it is less comfortable, because it’s slow. And as for editing, when you’re on a Mac, the TextMate editor is the absolute bomb.
My MacBook is in the living room playing Spotify songs at the moment, so let’s take the Linux road today in a virtual environment. Let’s use vim as a texteditor.
This is going to be lots of fun!

Yeah, okay, but I’m a bit lazy and after all, it’s Sunday evening.

Right. Let’s download a virtual machine that runs Ubuntu Server with a complete Ruby environment. Please do so and we’ll start the tutorial from there.

After booting the virtual machine, this what you’ll see:

Login with username ‘bitnami’ and password ‘bitnami’.
You”ll be prompted to change the password.
Next, change to root. To do so type ‘sudo -s’ :

Basic Linux housekeeping for starters:
sudo -s
apt-get update
apt-get upgrade
# install the vim editor
apt-get install vim
# set the network interface:
vim /etc/network/interface

Now the interfaces file opens. The IP address is set to dhcp by default, which we’ll change to static.
Hit the INSERT key to edit the file:

# The primary network interface
auto eth0
iface eth0 inet static

Now hit ESCAPE followed by :w and :q (for writing and quitting vim).
Set the DNS Server in /etc/resolv.conf:

vim /etc/resolv.conf

Now it’s time to restart the network:

/etc/init.d/networking restart

Now check with ifconfig if eth0 has the correct IP address. Because if this is the case, we can leave the VMWare console for what it is and connect to the virtual machine using Putty.
Oh. Apparently ssh is disabled on the virtual machine. Go:
mv /etc/init/ssh.conf.back /etc/init/ssh.conf
start ssh

Now we can connect to the appliance using Putty.
Accept the fingerprint securitywarning and login with bitnami and your password. Switch to root immediately with sudo -s (I always do so).

Eeuw, this is so boring. Where are those fancy dircolors? (Note: in some versions the dircolors are already enabled)

cd /home/bitnami
vim .bashrc
#paste this in the file:
if [ "$TERM" != "dumb" ]; then
[ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors"
[ -e "$DIR_COLORS" ] || DIR_COLORS=""
eval "`dircolors -b $DIR_COLORS`"
alias ls=’ls –color=auto’
#alias dir=’ls –color=auto –format=vertical’
#alias vdir=’ls –color=auto –format=long’

that’s much better.

So, how about Ruby On Rails then?
The Bitnami Ruby Stack came with an example project. Let’s start that up and check it out:

cd /opt/bitnami/projects/rubystack-2.1-0
#start the app:
ruby script/server
-bash: ruby: command not found

Hmm, that’s not working. We should add Ruby to the path.
vim /etc/environment
#hit INSERT to edit:
#hit ESCAPE followed by :w and :q

Now log off, log on and try again:

root@linux:/opt/bitnami/projects/rubystack-2.1-0# ruby script/server
=> Booting Mongrel
=> Rails 2.3.5 application starting on
=> Call with -d to detach
=> Ctrl-C to shutdown server

And now we can access the application at http://your-vm-ip:3000.

So, everything works apparently. Next time we are going to create our first ROR project.