Jump to main contentmickwood.com - Website Hosting & Design for Christian Organisations
Support

"If we don't know it's broken we can't fix it!"

Support FAQ Homepage

Can't find the answer?

Ruby on Rails & Ruby Gems

  1. How do I create a Ruby on Rails application?
  2. How do I deploy a Ruby on Rails environment?
  3. How do I install a Ruby Gem?

1. How do I create a Ruby on Rails application?

Overview

Below are instructions on how to create a Ruby on Rails test application and writing a very basic program.

Creating a Ruby on Rails Test Application

Steps

  1. Click on the icon for "Ruby on Rails"
  2. Check the box for "Load on boot?"
  3. Fill in the "App Name" box and name it "test"
  4. Application Path will be automagically filled in for you as public_html/test
  5. Select "production" for the Environment, which should already be selected as the default.
  6. Click "Create"
  7. To view your new application go to http://www.yourdomain.com/test/public/

You should now see a "Welcome aboard" message which is the default Ruby index page.

If you get a 400 Error, make sure to include the trailing slash "/" after "public" or you may not see the default Rails welcome page.

http://www.yourdomain.com/test/public/ <-- Correct
http://www.yourdomain.com/test/public <-- Incorrect

Now that you have created your RoR framework we will make a very basic RoR program. For this tutorial we will be using Pico, Putty and Windows.

Creating a Very Basic Ruby on Rails Program

Windows: This tutorial assumes it is the OS running on the computer you are viewing this page in.

Putty: The SSH program for connecting to the Linux server from Windows using SSH. If you don't have Putty you can download it here - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.

Pico: A Linux text editor install on the server.

Steps

1. Login to your shell account using Putty (or your favorite SSH program) using your username and password. Once logged in, navigate to your "test" directory that we created in the previous tutorial.

Command:

 [username@server ~]$ cd public_html/test

2. Execute this command from your Rails application directory ("test") to generate your Rails controller: 

Command:

 [username@server ~]$ ruby script/generate controller hello index

3. Now you need to build your program. You can use notepad or some other text editor, and upload the file, or you can edit it right in your shell using pico.

Command:

 [username@server ~]$ pico app/controllers/hello_controller.rb

You are now using the Pico text editor. You will see something similar to:

Code:

 class HelloController < ApplicationController

  def index
  end
end

Change this file so that it contains:

Code:

 class HelloController < ApplicationController

  def world
  @greeting = "hello world!"
  end
end


Press ctrl+x and type "y", then press enter to write the text to the file.

"def world" is a method called whenever users request http://www.yourdomain.com/hello/world

@greeting is a variable, and is also an object. The @ means it will be seen by the code in your application until the end of the request. 

Lastly we need to make the file "world.rhtml" in app/views/hello/world.rhtml by using Pico again:

Command:

 [username@server ~]$ pico app/views/hello/world.rhtml


Add this line of code to it, then save and exit.

Code: 

 <%= @greeting %>


Go back to your control panel, click on Ruby on Rails and make sure your application is running. If it shows as "Not Running", click the "Run" button in the "Actions" column for "Available Ruby on Rails Applications."

Once you have started the application, you can view it on the web:

http://www.yourdomain.com/test/public/hello/world/

Back to top


2. How do I deploy a Ruby on Rails environment?

Overview

Ruby on Rails is an open source web application framework for the Ruby programming language. It is often referred to as "Rails" or "RoR". Along with Ruby we've installed RubyGems and Mongrel for a fast and stable Ruby on Rails environment.

Deploying An RoR Environment

Steps

  1. First you will need to login to your control panel and click on the Ruby on Rails icon, to bring up the Ruby on Rails management interface that allows you to setup your Ruby environments. At this point you will need to give your application a name and setup it's path.

    NOTE: You set this path inside of your public_html directory your application's source code and configuration files can be viewable by anyone on the web.
  2. Once you have deployed your first environment, we will of course want to turn it on by clicking on the run icon next to the "Application's Name" in the "Manage Ruby on Rail's" interface. If this worked successfully you should seeing "running" under "status" and you should be able to click the URL icon under the Rails Server column and see a page that looks similar to this:

    This page means that the environment is up and running, and for the rest of your Ruby on Rail's application installation you will need to consult the application's installation guide.

If you pay close attention to the URL used for the application, you will see that it has a number like :12001 at the end of it, this is because Ruby on Rails does not use the standard Apache web server, but rather uses it's own called Mongrel. We can change these to be user-friendly. You will need to create a new subdomain or addon domain in cpanel, then click on the create rewrite button next to the rails application name in cPanel, select the desired domain name from the drop down box, and now, whenever you go to this domain it will display the RoR application.

Back to top


3. How do I install a Ruby Gem?

Overview

Ruby Gems are are collections of functions that allow you to perform tasks in Ruby. You will need to install a Gem before you can use it inside a Ruby program. This guide will show you how to install your own Ruby Gems, see existing gems installed, and even view documentation for those gems

Gems are installed directly from the RubyForge repository.

The Ruby Gems Management Page

You will need to login to the control panel and click the Ruby Gems icon to get to the Ruby Gems management page. From here you can perform all of the operations listed below.

Steps

Install a Gem

To install a gem, simply type the name of the gem and click Install Now. You can also search for gems and see available ones by using the buttons above the Install Now button.

Update, Reinstalling, and Removing Gems

You can update, reinstall, remove, and browse the documentation for a gem once it is installed by clicking on the appropriate buttons at the bottom of the Ruby Gems management page.

Checking Existing System-Wide Gems

You can click "Show System Installed Modules" to see a list of gems installed on the system. It is usually preferable to use these gems if possible. On all of our servers we have the basic Rails gems installed, along with a list of very commonly used gems.

Back to top


welcome | name | hosting | design | content | promote | update | showcase | support | general information

Showcase Update Promote Content design Hosting Name Welcome