With POW 3.2 I’ve been noticing every once in a while it’ll choke and try and burn out my CPU, thankfully there’s a temporary fix with the PRE 4.0 release.

This you can install via

curl get.pow.cx | VERSION=0.4.0-pre sh

More info here

Today we’ll install the latest stable version of Ruby on an Ubuntu Linux machine, let’s begin…

Fire up Terminal and type the following to install RVM:

bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )

Once installed you’ll have to add the following to the end of your .bashrc file to make rvm accessible from the prompt:

vim ~/.bashrc

Scroll down to the bottom, hit I to switch to insert mode and paste the following into the file, then hit ESC to switch to select mode, then type :wq to write the changes and quit the file.

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

Run this to refresh your terminal and pick up the changes:

source ~/.bashrc

Next install the pre-requisites for Ruby via:

sudo aptitude install libc6-dev libssl-dev libmysql++-dev libsqlite3-dev make build-essential libssl-dev libreadline6-dev zlib1g-dev

And install Ruby

rvm install 1.9.2 -C --with-readline-dir=/opt/local
rvm 1.9.2

Check it’s installed via:

ruby -v

And finally set it to default as:

rvm 1.9.2 --default

Job done.

Tonight I got the macbook out to run thru the ‘15 minute blog video’, one word… WOW! this thing is powerful, and way intelligent.

Thought I’d write some notes on how to get Ruby on Rails running on your macbook too, as if you’re a geek like me (and wanting to cut your dev time in half) you’re gonna want to, so here goes…

To setup Ruby on Rails on your Macbook, first download Locomotive, unpack the .dmg file and drag it into your applications directory.

Do the same for MAMP, downloading it and putting that in your apps dir (MAMP gives you Apache, MySql and PHP all in one tidy package). You may need to register or give your email address to obtain a copy but other than that it’s all good.

Once you’ve done that, fire up MAMP and Locomotive; you now have a web server and Ruby on Rails running on your desktop, pretty cool eh?

Point your browser to ‘http://0.0.0.0:3000/’ to see it in action.

However your gonna have trouble accessing your mini MySql server unless you switch to Locomotive and enter ‘/Applications/MAMP/db/mysql/’ in the Preferences/Terminal/’Additional Paths’ box. Doing this will tell Locomotive where to find your database server.

Now to create your first Ruby app, in Locomotive, select ‘Applications/Create New…’ then type the name of your new app.

To edit the source of your app, in Locomotive, select ‘Edit in TextMate’ and your away (TextMate is a powerful text editor built for the mac, you need to purchase it, $39, but it’s well worth it; trust me, includes lifetime updates so never need to again).

…one thing though, to make your app talk to your database fully, in TextMate, open the ‘config’ folder and edit ‘database.yml’, make your settings like;

development: adapter: mysql socket: /Applications/MAMP/tmp/mysql/mysql.sock database: blog_development username: root password: root host: localhost

This will tell Ruby to connect to the MySql socket and use the default username & password you get set to on first install of MAMP.

Restart MAMP & Locomotive and get on with the lessons at www.rubyonrails.org

Final words, Ruby is an intelligent language so what you name things will mean a lot more, things like making a table of posts for a blog; call it ‘posts’ and Ruby will know what your intended use for them is, like calling a to-do list ‘to-do’; things have more meaning.

Ruby hasn’t been around long, only since 2004, but is gaining a massive following due to the speed in which you can build complex web applications. The web pages themselves ‘.rhtml’ are generated as you run them.

To add new packages, or ‘gems’, use the ‘gem install’ command when in Locomotive (Applications/Open Terminal). And to generate new MVC parts, type ‘./script/generate ‘, Ruby makes heavy use of the MVC model, keeping the three components of your application separate at all times; minimising the time spent bug-fixing your app.

Drop me a line if you get stuck,

Till next time,

After a while of development with Ruby on Rails, you build up a few notes on what you should always have, or recommended setups. So to complement all my other notes, here’s a little collection of Ruby Gems that I’d recommend you add to your collection, and some command lines to help you.

Startup + Deployment

Basics

ruby -v
// returns ruby version

rails [app]
// creates new app in current directory

script/generate
// generates templates, models, views, etc.

rake db:migrate
// runs pending database migration plans

script/server
// starts mongrel or webrick web server

script/server -p 3030 -e production
// starts mongrel in production mode at port 3030

script/server -d
// starts mongrel in development mode silently
// terminte it with these two:

ps aux | grep mongrel
// shows active processes named 'mongrel'

kill 31290
// terminate process 31290

Adding + Removing Gems

sudo gem install [gem]
// installs gem [gem]

sudo gem uninstall [gem]
// uninstalls gem [gem]

Required Gems

sudo gem install rails --include-dependencies
// the web framework ruby sits on

sudo gem install mongrel --include-dependencies
// mongrel is RoR's webserver

sudo gem install mongrel_cluster
// cluster-based mongrels

gem install capistrano -v 1.4.1
// makes it easy to deploy your RoR app

sudo gem install deprec -v 1.2.3 -y
// adds deprec deployment recipies

Capifying your App

To make your app ready for deployment to your remote server, do:

cap --apply-to .
// creates the capify .caprc file

deprec --apply-to . --name myapp --domain myapp.com
// generate your apps deploy.rb file

cap show_tasks
// show available capistrano tasks

Getting Cutting-Edge Builds

Freezing your Rails to the Edge

When building your app, you may want to make sure it will only ever use the Ruby version you’ve got now; rather than the one you might have in the future (if you upgrade ruby later). You know, if certain commands get depreciated later on, or if the command you use now doesn’t work in the next version of ruby, but you need to upgrade your server’s Ruby build for the other apps.

…to freeze rails, navigate to your apps dir, then run;

rake rails:freeze:edge
rake rails:update

…un-freeze it with;

rake rails:unfreeze

…to check what versions your running, try;

script/about

Gem Maintenance

Updating Ruby on Rails

gem update
// updates all installed gems

gem update --system
// updates 'gem' -> latest version

gem cleanup
// deletes any previous unneeded gem files

rake rails::update
// updates your app to latest rails release

Extra Gems

sudo gem install termios --include-dependencies
// wrapper for the UNIX termios command
// prevents passwords you enter in
// Capistrano from being displayed in 
// your Terminal for all to see

sudo gem install tzinfo --remote
// timezone library, provides
// daylight-saving awareness and 
// different time zones

sudo gem install redcloth
// adds support for Textile formatting

sudo gem install feed-normalizer
// ruby RSS/ATOM feed reader + dependencies

sudo gem install mysql
// builds in better mysql performance