Checklist for Running Ruby on Rails on Bluehost
Kudos to Bluehost for adding Rails hosting, but you might have found getting more than a trivial example running is an exercise in frustration. The following checklist details at least one successful path to getting a full Rails app up and running. (Much of the basic outline comes from the following Bluehost knowledgebase article, but it tends to leave out some details, especially newer things like ActiveRecord migrations.)
Setup Directories on Bluehost
Bluehost suggests setting up a working directory for your rails projects. Reasonable enough just use the wonderful CPanel ssh terminal and create it at the top level of your home directory:
% cd ~ % mkdir rails % cd rails
Next you want to startup your first rails project. This may seem a bit bizarre, since you may have a perfectly good rails project already. Lets just assume you want to upload the sample project from Agile Web Development with Rails, the Depot project.
% rails depot % cd depot
Point a New Subdomain to Your Rails App
Now it’s time to setup a subdomain for your little application. Bluehost gives you plenty of these so one per rails app is no big deal. We’re just going to assume we’re using example.com so the final subdomain will be depot.subdomain.com. Just go into CPanel and add depot as a new subdomain. Now we want to point to it in our ssh session again:
% cd ~/public_html % ln -s /home/YOUR_USERNAME/rails/depot/public depot
As a test that things are going right so far you can check out http://depot.example.com/ and you see the familiar rails default page. Nice but not exactly what you were hoping for.
Setting Up the Databases
First you need to add a database user. cPanel prepends your own Bluehost username to everything so just be aware. Add the database user by going to cPanel choosing the MySQL databases and adding a user. If you pick ‘rails’ the name will be
1
|
username_rails
|
.
Next, just add two databases dev and prod. You won’t need a test database probably because you won’t be running your unit/functional tests on the Bluehost server. So same MySQL link in cPanel and just name it ‘depotdev’. (You can’t use an underscore since it just ignores it anyway.) Since it appends the username it will become
1
|
username_depotdev
|
. Then you repeat the steps again for the production database and name it ‘depotprod’ so that you have another database
1
|
username_depotprod
|
.
Finally you give the
1
|
username_rails
|
user access to the the two databases
by first selecting
1
|
username_rails
|
from the user pulldown menu and then
1
|
username_depotdev
|
from the database pulldown. Go ahead and give it all permissions and click on ‘Add User to Db’. Repeat for
1
|
username_depotprod
|
.
Configuring the Database Connection
Of course here you’re going to edit
1
|
config/database.yml
|
on your local machine. It should look something like:
development: adapter: mysql database: username_depotdev username: username_rails password: password host: localhost
production: adapter: mysql database: username_depotdev username: username_rails password: password host: localhost
Then FTP the file up and replace
1
|
~/rails/depot/config/database.yml
|
.
Migrating the Database Schema
Migrating your database using ActiveRecord migrations starts with FTPing over everything in your
1
|
depot/db/migrate
|
directory locally. Then log into your server using the cPanel SSH client and run:
% cd ~/rails/depot % rake db:migrate % rake db:migrate RAILS_ENV=production
Both of the migrate commands should show some schema migration logging comments. If not you probably need to check the syntax in your database.yml file for errors. This migrates the schema to both the dev and production instances.
Migrating the Application Code
Next step is to FTP over all of the files in
1
|
depot/app
|
on your local machine to the server at
1
|
~/rails/depot/app
|
.
Since you’re application may need some sample data you can add it through phpMyAdmin, SQL scripts, or a Rails scaffolding.
Switching to a Default Production Environment
Rails by default assumes you’re running in development mode. There are lots of nice ways to change the RAILS_ENV environment variable, but since Bluehost is a hosted solution there is a pretty simple hack that is guaranteed to work. Simply uncomment the following line in your
1
|
config/environment.rb
|
file:
# Uncomment the line below to force Rails # into production mode when you don't # control web/app server and can't set it # the proper way # ENV['RAILS_ENV'] ||= 'production'
Then FTP the file over to your Bluehost account. You’ll probably want to comment out the line in
1
|
environment.rb
|
again for you local development.
Positive Feedback
Just point your web browser at the URL assuming you have controller named ‘store’ and a method named ‘list’.
http://depot.example.com/store/list
Now do a little victory dance or eat some M&Ms, your choice.
Iteration Zero Team Charter
Simon Baker has a very good example of a team charter for an Agile project developed in Iteration Zero. It spells out how the team will do estimating, track progress, do TDD, implement continuous integration, and coding standards. This is the sort of example based template you can take and show your own team as a starting point. And apparently Simon also has very good whiteboard skills as evidenced by some of the pictures of his chartering mind maps.
The Agile Toolkit Podcast
It’s not the most updated technical podcast around, not the most polished sounding, and follows pretty much just an interview format, but I really like when the occasional new Agile Toolkit episode pops up. The host Bob Payne follows a simple format:
- Attend a conference.
- Corner as many good speakers as you can.
- Get them to sit down for about 30 minutes and just talk.
Almost all the guests are from two conferences, Agile 2005 and No Fluff Just Stuff Northern Virgina 2006. The guests range from Bob Martin to Jared Richardson of Ship It!. I’m hoping Bob gets the chance to attend a few more conferences this year.
Sprint Without A Burndown Chart
I’ve been experimenting with leaving off a sprint burndown chart for the last two sprints on a project. Everything critical is tracked on a corkboard and I have a separate chart that shows where we are as far as moving content onto a new intranet. So far no one’s missed it.
Part of the reason for the lack of the burndown chart is that I no longer record the sprint backlog in Excel so I don’t get an easily generated chart. The other reason is I can’t see that it’s providing much value. Some Scrum Masters focus too much on the burndown and whether the team is above or below the line. The focus is on the artifact of the process and not what’s really going on with the team. If you hold daily meetings as a Scrum Master and you don’t already know about a real problem developing then you’re really not doing your job.
Release burndowns are valuable as a means of estimating approximately how many story points or ideal days the team is able to deliver for an average Sprint. Unfortunately until at least three Sprints are done this doesn’t tell you a whole lot either.
Ruby Versus Java Conventions
Having spent a long time almost exclusively coding Java since about 2001. I have some mental baggage when it comes to adjusting to Ruby. Excepting some tinkering in PHP and Python in the last five years I’ve primarily been living in an IDE with Java when I actually got to code.
I realize I have this bias, and I’m adjusting, but a small bug fix I submitted to RSpec shows that I still probably have more adjustment to do. The problem isn’t important, and in fact it was just a change to one line of code that was necessary.
The line of code was:
def method_missing(sym, *args, &block) if __is_sweetened? sym object = self calls = sym.to_s.split("_") while calls.length > 1 call = calls.shift object = object.__send__(call) break if call == "be" end return object.__send__(calls.join("_"), *args, &block) end __orig_method_missing(sym, *args, &block) end
The important line is
1
|
break if call == "be"
|
. The context isn’t critical, but essentially it needed to add conditions to only break if the next element in the array wasn’t the strings ‘a’ or ‘an’. In my head I thought there was probably a nice clean Ruby way to do this, and heck Array has a lot of nice convenience methods, so I started there.
My first attempt came up as:
break if call == "be" && (calls.first != "a" || calls.first != "an")
I found the
1
|
first
|
method from Array and I liked that, but the rest of the conditional felt exactly like something I’d write in Java except it would have been:
break if call == "be" && (calls[0] != "a" || calls[0] != "an")
OK, time for a little refactoring for readability. Extract out the conditional to a method and give it a better name.
break if call == "be" && a_or_an_follows_be(calls) ... def a_or_an_follows_be(calls) return (calls.first != "a" || calls.first != "an") end
At this point I figured it was reasonable even if not probably the most Rubyesque. Luckily the new release of RSpec fixed this bug and I was able to see what they did:
break if call == "be" unless ["an","a"].include? calls[0]
Much more concise, I would have never thought of just using a simple two element array.