Software dev, tech, mind hacks and the occasional personal bit

Category: Technical

Ruby on Rails Hosting, Setup And Migration

I’ve been doing a little rails of late.. Here’s a summary of the stuff that I’ve learnt.

What hosting should I use in Australia for rails?

NOT JUMBA – SEE UPDATED REVIEW BELOW

I’m using jumba (http://www.jumba.com.au). Jumba is very cheap (~$30AUD/year), and they give you shell access, mysql etc. However, there was a period of several weeks when they moved me to some server without an install of rails and kept promising to install rails and never did. I finally got them to move me back to their main server which has rails installed. It was a painful process, so I’m not sure if I would recommend them. That being said, things are going OK at the moment, and I’ve got a few development apps up and running on their service.

UPDATE 29 March 2006: Jumba summarily stopped rails support without notice and was rude when I contacted them about it. I would not recommend Jumba for web hosting anything – they have frequent down time, server switches and reboots and their low price is made up for by the amount of time you waste. They used to be OK, but no longer. I’m in the market for a new host, will post on how it goes.

How to set up rails applications in your home directory (in public_html) under a UNIX/Apache/cgi/fcgi environment

  1. Upload or create your application in your home directory. Eg, ~/MyRailsApp/
  2. In your public_html directory, create a soft link to the public directory of your app. Eg,
    ln -s ~/MyRailsApp/public ~/public_html/MyRailsApp
  3. Make sure dispatch.fcgi in the ~/MyRailsApp/public directory is executable. If not, chmod it a+x.
  4. Confirm that dispatch.fcgi has a valid path to ruby on the first line. If you’ve created this project on another machine, you’ll quite possibly need to update the path. The path is often something like ‘#!/usr/local/bin/ruby’, but check what it is under your system with ‘which ruby’. Special note for InstantRails users – you’ll always need to update the path when uploading to unix hosting, as instant rails uses a windows style path with the slashes the other way around.
  5. Update your ‘database.yml‘ file (in the ‘config‘ directory of your app) with correct database names, user names and passwords.
  6. Run ‘dispatch.fcgi‘ (in the ‘public’ directory of your app). If you see an ‘Internal Server Error’ message, you know things are going OK. If you’ve got the path to ruby wrong on the first line, or some other similar problem, you’ll find out about it here, where as if you run through the web, you don’t get these sorts of problems reported in an easy to understand way.
  7. Check out your running system in the browser (eg, browse to http://myhostingcompany.com/MyRailsApp/)

Tips for trouble shooting rails errors

  1. A good place to start is by reading your logs in the ‘log’ directory of your rails app. If you’re running a development configuration, have a read of ‘development.log’.
  2. Try manually running ‘dispatch.fcgi‘ in the ‘public’ directory of your app. If you get an ‘Internal Server Error’ message printed out on the console, it’s probably working ok. Alternatives to this are reports of missing files and unable to find ruby – often these aren’t shown when browsing to your web site.


Rails problems and solutions

1. Browser and logs show: Application Error – Rails app failed to start properly

I got this after my app was moved from one unix host to another by my hosting company. I tried heaps of stuff to try and resolve this. Eventually I created a brand new dummy project on the unix host called ‘Test’ and Test worked fine from the browser. I then tried my original project again and suddenly it worked fine! It has been working fine since. I can only imagine that there was some sort of problem in temporary files or similar which got flushed. No good explanation for this currently.

2. in `start_engine’: undefined method `add_path’ for Controllers:Module (NoMethodError)

I got this one when migrating a project from rails 1.1 to a later version of rails. The solution is to force update your rails engines:

script/plugin source http://svn.rails-engines.org/plugins
script/plugin install engines –force
script/plugin install login_engine –force

3. My app works fine if there is a trailing slash on the url. Otherwise, I get a ‘Bad Request’ error page. Eg, ‘http://myhost.com/myapp/’ works, but ‘http://myhost.com/myapp’ does not work.

Add a RewriteRule to the .htaccess file in your application’s public folder:
RewriteRule ^.*myapp$ http://%{HTTP_HOST}/myapp/ [R=301,L]

My basic .htaccess rewrites are as follows:
RewriteEngine On
RewriteRule ^.*myapp$ http://%{HTTP_HOST}/myapp/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

I tried removing the RewriteCond !-f, and my pages lost their styles. I think the condition allows the rails framework to load .css files directly without having the requests go through dispatch.fcgi.

Book Review: UML Distilled

UML Distilled: A brief guide to the standard object modelling language
(3rd Edition)
by Martin Fowler

UML Distilled is good. It is written carefully and concisely and has been heavily revised to cover UML 2. It is a opinionated book – it presents Martin Fowler’s view of UML. This is a good thing. Fowler concentrates on the parts of UML that he has found widely used in the industry, and the most useful in his own work. Fowler is not bound by the UML specification, he also describes “non-normative” diagrams (ie, variations on UML which are not standard but widely used). Fowler often provides his own view on a particular diagram or component. For example, I’ve often wondered when to use aggregation rather than association in a class diagram. Fowler cleared this up for me:

“Aggregation is strictly meaningless; as a result, I recommend that you ignore it in your own diagrams. If you see it in other people’s diagrams, you’ll need to dig deeper to find out what they mean by it. Different authors and teams use it for very different purposes.”

UML Distilled starts with an introduction about UML’s history and aims, and then a rapid look at different development methodologies and where to fit UML into them.

The core of the book covers the following diagrams/specs:

Class Diagrams
Sequence Diagrams
Object Diagrams
Package Diagrams
Deployment Diagrams
Use Cases
State Machine Diagrams
Activity Diagrams
Communication Diagrams
Composite Structures
Component Diagrams
Collaborations
Interaction Overview Diagrams
Timing Diagrams

Class diagrams and sequence diagrams are covered in detail, the other diagrams more briefly. The book is quite short, but gives enough information on each topic to allow you to understand and draw the diagrams. At the end of each chapter, there is a helpful “where to find out more” section and a “when to use this type of diagram” section.

There is also an appendix at the end of the book on changes between various versions of UML.

The book is surprisingly easy to read. Fowler’s style is clear and friendly and examples are well chosen.

My only complaint is that perhaps the book could have been a little longer to allow a bit more detail on some of the diagram types. I would have liked to have read a little bit more on object diagrams in particular.

I’d recommend the book to anyone who wants a rapid and concise introduction to or revision of UML 2.

Rating: 9/10

Book Review: My Job Went to India, 52 Ways to Save Your Job

Full Title: My Job Went to India (And All I Got Was This Lousy Book), 52 Ways to Save your Job

Author: Chad Fowler of the Pragmatic Programmers

185 pages, Paperback

An interesting book written by Chad Fowler, who spent 1.5 years in India hiring and managing an outsourced team of developers. The book’s main focus is on how you can make yourself as, a developer, more valuable to your company / community so that your job is not outsourced. There are quite a lot of valuable and interesting ideas in the book for professional development, and “getting your name out there”. The book also gives the reader some idea of what development is like in India, some tips and the pluses and minuses of outsourcing.

The style of the book is conversational, and easy to read. I finished it in 2 days. I’d recommend it to developers wondering about outsourcing and looking for some tips on professional development.

Rating: 8/10

Page 15 of 15

Powered by WordPress & Theme by Anders Norén