Troubleshooting: Ruby on Rails | Bluehost Support
Support
  1. bluehost knowledge base

Troubleshooting: Ruby on Rails

FAQ

Question:

What Ruby on Rails version and Gems are installed?

Answer:

You may check the version of Ruby on Rails on your server by logging in to SSH and typing the following command:
> rails -v
Rails X.X.X will be displayed. 

You can see what gems are installed and/or install gems from the cPanel by clicking on the icon RubyGems under the "Software/Services" category.


Question:

How do I install my own Ruby Gems?

Answer:

  1. Using File Manager in your cPanel make a copy of the .bashrc file in your root directory, name it .bashrc.bak.
  2. Now edit the .bashrc file and add the following to the end of the file:
    • export GEM_HOME=$HOME/ruby/gems
    • export GEM_PATH=$GEM_HOME:/lib/ruby/gems/1.9.3
    • export GEM_CACHE=$GEM_HOME/cache
    • export PATH=$PATH:$HOME/ruby/gems/sass-3.4.21/bin/
  3. When using a rails application, make sure you add the following to your ./config/environment.rb:
    • ENV['GEM_PATH'] = '/path/to/your/home/ruby/gems:/lib/ruby/gems/1.9.3'

Troubleshooting

Problem:

When I attempt to execute my Ruby on Rails application I receive "500- Premature end of script."

Solution:

This error generally has two potential causes:

  • The file permissions are not set to allow the dispatch.cgi to execute properly.

    Chmod the dispatch.cgi to 0755.

  • The path to Ruby is is incorrect in the dispatch.cgi file.

    The first line of the file is called the hashbang-- it sets the location of the interpreter (in this case ruby).

    Change the hashbang to the correct path to Ruby (/usr/bin/ruby).
    The first line of the dispatch.cgi file should look like this:
    #!/usr/bin/ruby


Problem:

Rails Troubleshooting!

Solution:

Make sure you have SSH Enabled  in order to follow these directions as it is required to install gems locally.

1. Add the following lines to your $HOME/.bashrc file (these can be copy and pasted):
   export GEM_HOME=$HOME/ruby/gems
   export GEM_PATH=$GEM_HOME:/lib64/ruby/gems/1.9.3
   export GEM_CACHE=$GEM_HOME/cache
   export PATH=$PATH:$HOME/ruby/gems/bin
2. Now, you'll have to edit the source file for the rack gem. This *should* be located here:
   $HOME/ruby/gems/gems/rack-1.1.6/lib/rack/handler/fastcgi.rb
Just comment out line #7 so it looks like this:
   #alias _rack_read_without_buffer read
3. Now modify the applications environment.rb file so that the correct gem path is included. This line should go up at the top before the version of rails is specified:
  ENV['GEM_PATH'] = '/path/to/their/home/ruby/gems:/usr/lib/ruby/gems/1.9.3'
4. Kill off fastcgi processes.

Problem:

My Ruby on Rails installation keeps displaying a '404 Not Found' error.

Solution:

Please create a .htaccess file inside the public folder with the following code:
# General Apache options
AddHandler fcgid-script .fcgi
AddHandler cgi-script .cgi
Options +SymLinksIfOwnerMatch +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
# 
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
# 
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#   Alias /myrailsapp /path/to/myrailsapp/public
#   RewriteBase /myrailsapp

RewriteBase /
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

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
This should fix the 404 error.