Ruby on Rails

6th November
2009
written by simplelight

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
14th September
2009
written by simplelight

The complete guide to handling web sessions in a Ruby on Rails framework

5th July
2009
written by simplelight

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:

  1. Install the gem: sudo gem install cldwalker-hirb –source http://gems.github.com
  2. Start the console: ruby script/console
  3. Require Hirb: require ‘hirb’
  4. Enable it: Hirb.enable
  5. Try it: x = Model.find(:all)
18th June
2009
written by simplelight

jQuery Tools is a great UI javascript library for web designers

11th April
2009
written by simplelight

WebDesignerWall has a great introductory jQuery tutorial. There are ten tutorials, including ones on animated hover effects, collapsible panels and menu accordions.

2nd April
2009
written by simplelight

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', :o nly_path => false},
:with => "'correct=#{escape_javascript(@text)}&guess='+encodeURIComponent(value)" %>
[/ruby]

28th February
2009
written by simplelight
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'
22nd February
2009
written by simplelight

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.

8th February
2009
written by simplelight

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:

  1. Download and unzip Bort into project folder
  2. Edit the database.yml and the settings.yml files
  3. Create the database: mysqladmin -u <username> -p create <db_name_development>
  4. If you’re using Dreamhost: add ‘host: mysql.<dbhostname>.com’ to your database.yml file (in the production environment)
  5. rake db:migrate
7th February
2009
written by simplelight

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.

Previous
Next