Ruby on Rails
After downloading the latest Ubuntu desktop appliance from VMware, the following steps are required to get a Rails environment up and running:
Create a new user and add all the required access
Get Ubuntu up to date
sudo apt-get update sudo apt-get dist-upgrade
Install compile packages
sudo apt-get install build-essential
Install Ruby, MySQL and the Open SSL library
sudo apt-get install ruby ri rdoc mysql-server libmysqlclient15-dev libopenssl-ruby ruby1.8-dev
Install Sun Java
sudo apt-get install sun-java6-jre sun-java6-plugin
Get the latest ruby gems from RubyForge
wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.5.tgz tar xvzf rubygems-1.3.5.tgz cd rubygems-1.3.5 sudo ruby setup.rb
Remove the .tgz file and erase the rubygems-1.3.5 directory too.
Create the following symbolic links
sudo ln -s /usr/bin/gem1.8 /usr/local/bin/gem sudo ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby sudo ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc sudo ln -s /usr/bin/ri1.8 /usr/local/bin/ri sudo ln -s /usr/bin/irb1.8 /usr/local/bin/irb
Install Rails
sudo gem install rails
Add Github for legacy gems
gem sources -a http://gems.github.com
Switch to Gemcutter for primary gem repository
sudo gem install gemcutter gem tumble
I use the Rails console mainly to poke around in my database. Unfortunately the display of the records returned leaves a lot to be desired. Hirb solves this problem perfectly! Here are the quick steps you need to get the basic functionaliy:
- Install the gem: sudo gem install cldwalker-hirb –source http://gems.github.com
- Start the console: ruby script/console
- Require Hirb: require ‘hirb’
- Enable it: Hirb.enable
- Try it: x = Model.find(:all)
WebDesignerWall has a great introductory jQuery tutorial. There are ten tutorials, including ones on animated hover effects, collapsible panels and menu accordions.
I was using the Rails helper observe_field to monitor a text entry form on my web app. I couldn’t figure out why the relevant method was not being called until I realized that it was happening every time there was a single quote in the text entry. The solution is simple. Use the escape_javascript function as shown below:
[ruby]
<%= observe_field :guess,
:frequency => 0.5,
:update => 'ajaxWrapper',
:url => {:action => 'feedback',
nly_path => false},
:with => "'correct=#{escape_javascript(@text)}&guess='+encodeURIComponent(value)" %>
[/ruby]
ssh-keygen -t rsa
Then use this command to push the key to the remote server, modifying it to match your server name.
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
redirect_to :action => ‘list’ forces the clients browser to request the list action.
render :action => ‘list’ will render the template list.rhtml without calling or redirecting to the list action.
I highly recommend Bort when you’re starting a new Ruby on Rails project. Assuming you’re using MySQL, the following steps are all that are necessary to get started:
- Download and unzip Bort into project folder
- Edit the database.yml and the settings.yml files
- Create the database: mysqladmin -u <username> -p create <db_name_development>
- If you’re using Dreamhost: add ‘host: mysql.<dbhostname>.com’ to your database.yml file (in the production environment)
- rake db:migrate
The following gems and plugins are the most popular as of Nov 12th, 2008:
- Javascript Framework: jQuery (56%), Prototype (43%)
- Skeleton: Bort
- Mocking: Mocha
- Exception Notification: Hoptoad
- Full text search: Thinking Sphinx
- Uploading: Paperclip
- User authentication: Restful_authentication (keep an eye on Authlogic)
- HTML/XML Parsing: Hpricot
- View Templates: Haml
NewRelic has a good article on the state of the Rails stack.

