Loading...

Knowledge Base

Troubleshooting Ruby on Rails Errors on Bluehost

Ruby on Rails is a powerful web application framework written in the Ruby programming language. While it allows developers to build applications quickly and efficiently, occasional issues can arise during setup or deployment. This article walks you through frequently asked questions and provides solutions for common Ruby on Rails errors, especially when hosting on Bluehost.



Frequently Asked Questions

Q: What version of Ruby on Rails is installed?

A: 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.

 

Q: How do I install my own Ruby Gems?

A:

  1. Using File Manager, make a copy of the .bashrc file in your root directory and 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'

Common Ruby on Rails Errors and How to Fix Them

Ruby on Rails Error 500

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 dispatch.cgi to be executed properly. Chmod the dispatch.cgi to 0755.
  • The path to Ruby is incorrect in the dispatch.cgi file. The first line of the file is called the hashbang, which 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

Gems Installation

Problem

Ruby on Rails Troubleshooting for installation

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 copied 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
  1. Now, 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
  1. 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'
  1. Kill off fastcgi processes.

404 Not Found

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 necessary codes. See the examples below:

  • Apache options:
    AddHandler fcgid-script .fcgi
    AddHandler cgi-script .cgi
    Options +SymLinksIfOwnerMatch +ExecCGI
  • If you don't want Apache to rewrite requests, use the rewrite rules below:
    RewriteCond %{REQUEST_URI} ^/notrails.*
    RewriteRule .* - [L]
  • For better performance, you can replace the cgi dispatcher with fastcgi:
    RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
    RewriteEngine On
  • Set the RewriteBase in your file if you access Rails via the Alias directive:
    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]

Summary

Troubleshooting Ruby on Rails errors on Bluehost doesn't have to be daunting. Whether you're facing a 500 Internal Server Error, a 404 Not Found issue, or struggling with Ruby Gems installation, this guide offers step-by-step instructions to help you resolve common problems quickly. By ensuring your server permissions, .htaccess configurations, and gem paths are correctly set, you can run your Ruby on Rails application smoothly on Bluehost.

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 888-401-4678
    • International: +1 801-765-9400

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.

Did you find this article helpful?

 
* Your feedback is too short

Loading...