Kattare Internet Hosting Home | Home | Services | Contact Us | Order Online |   whitespace image
  Kattare I/S: View FAQ Answer | Webmail | News | FAQ | Members Login |   whitespace image
tail end of the Kattare logo Toll Free: (866) KATTARE -or- (877) KATTARE
Local: (541) 753-1079
keyboard image  whitespace image
You've got Q's? We've got A's.  whitespace image
greenspace image for php hosting, jsp hosting, servlet hosting, java hosting website

Home

Contribute Hosting!

Hosting Services

Java Hosting
  JBoss Hosting
  JSP Hosting
  GlassFish Hosting
  Servlet Hosting
  Tcat Hosting
  Tomcat Hosting

Standard Hosting
  Perl Hosting
  PHP 4 Hosting
  PHP 5 Hosting
  Ruby Hosting

Dedicated Servers
Server Co-Location

Domain Lookup
Join Us Today!

Members

Control Panel
  Ticketing
  Webmail
F.A.Q.
Recent News
Referral System
Spam Blocking

Company

About Us
  History
  Privacy Policy
  Sites We Host
  Strategic Partners
  Terms of Service
  Trademarks
Contact Us
  Phone / Fax
  Mail / Email
  SMS Text


Verify Kattare Internet Services

Documentation

Kattare is dedicated to making your hosting experience as painless as possible. That means making as much help and documentation available as possible. If you have a question that you think would be helpful to have here, please [Submit your Question].

Quick Links
 [Getting Started
 [JSP & Java
 [Ruby & Rails
 [Email & Webmail
Category
Ruby Programming (incl Rails)
Question

Last Modified: Jul 16, 2010

How do I setup Ruby On Rails? (with FastCGI)
Answer

First things first!

The first thing you'll need to do is setup your ruby environment at Kattare. Please see this FAQ entry: Setting up your Ruby environment with RVM

A little about Ruby on Rails

Ruby on Rails can be great. It can also be a huge pain in the tailpipe. Ruby and Rails have proven over the last few years to have a very quickly changing code base and trying to keep up with it all is near impossible even for the seasoned pro. From version to version things WILL break. As we learn more, we'll share what we know here.

For now, this has been tested using our system default of Ruby 1.8.6 w/ Rails 0.13.1 and with a RVM environment of Ruby 1.8.7 w/ Rails 2.3.8. Yes, our system default is old, Kattare got into Ruby very early on, and many of our clients have deployed apps on the initial environment. Since then we've been stuck, because nearly every successive version breaks something integral. Which is why RVM is so nice and we're very happy to have it!

Things you'll have to track

In this example,

<domainname> = burnside.kattare.com
<document_root> = ~/burnside_kattare_com
<appname> = burnside_on_rails
<controller> = Hello
<username> = burnside
<action> = hello

On the CLI

Here's the play by play from the command line...

cd ~<username>

Use the rails command to setup the application base.

rails <appname>
Important! If using rails >= 2.3.3 the fcgi dispatchers are not included unless you specify --with-dispatchers to your rails command.
IE: rails --with-dispatchers <appname>

Link the application base into your document root.

ln -s ../<appname>/public <document_root>/<appname>

vi/pico <appname>/public/.htaccess

change dispatch.cgi to dispatch.fcgi, this will speed things up significantly.

If the .htaccess file does not exist, (rails >= 2.3.3?) here is what the content should be:
    AddHandler fastcgi-script .fcgi
    Options +FollowSymLinks +ExecCGI

    # Redirect all requests not available on the filesystem to Rails
    RewriteEngine On
    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

    # In case Rails experiences terminal errors
    # Instead of displaying this message you can supply a file here which will be rendered instead
    # 
    # Example:
    ErrorDocument 500 /500.html
Next you need to generate a controller.

cd <appname>
./script/generate controller <controller> (my controller is 'Hello')
vi/pico app/controllers/<controller>_controller.rb ('hello_controller.rb' for me.)
class HelloController < ApplicationController
  def hello
  end
end
And then you setup a view:

vi/pico app/views/<controller>/<action>.rhtml
<html>
  <head>
    <title>Hello Rails World</title>
  </head>
  <body>
    <h1>Hello from Rails on Kattare!</h1>
    <p>The current time is <%= Time.now %></p>
  </body>
</html>

Test!

For my setup, my url came out to be: http://burnside.kattare.com/burnside_on_rails/Hello/hello

Yours would be something like:

http://<yourdomain>/<appname>/<controller>/<action>

One thing I noticed is that Rails startup IS NOT FAST. In fact, it's so slow that my initial request frequently times out because FastCGI gives up after about 30 seconds. Then if I wait a minute or so, it works.

When your changes are not getting picked up

Sometimes you may need to kill off the fast cgi processes to force the system to restart your app. To do this you execute these commands:

killall dispatch.fcgi
killall -9 dispatch.fcgi

If you get a Routing Error

You may need to add the following to your config/environment.rb:

After the "Fails::Initializer.run do" line I had to add:

config.action_controller.relative_url_root = "/burnside_on_rails"

For you it would be:

config.action_controller.relative_url_root = "/<appname>"

If your app is not picking up your gems

vi/pico <appname>/public/dispatch.fcgi

Change dispatch.fcgi to use gems by changing
    require File.dirname(__FILE__) + "/../config/environment"
    require 'fcgi_handler'
to
    require 'rubygems'
    gem 'fcgi'
    require 'fcgi'
    require File.dirname(__FILE__) + "/../config/environment"
    require 'fcgi_handler'

[FAQ Main] [Submit a Question]

[Back to Category "Ruby Programming (incl Rails)"]


whitespace image
green spacer

 [Getting Started]  [JSP & Java]  [Ruby & Rails]  [Email & Webmail]

Kattare Logo
whitespace image
 
whitespace image
whitespace image