Sandbox Environment Tutorial

Introduction

Here you will find information about getting started with a PowerRuby sandbox environment.  A sandbox environment is a mechanism to allow multiple developers to build Rails applications on a single IBMi instance without stepping on each others toes.

Sandbox environments are located in the IFS and are accessed by logging into PASE using SSH.  Once logged in the user will only be able to change directory (cd) up to the root of their environment (they can't see or access other parts of the system).

This tutorial is mostly for describing sandbox differences from "Create a new rails app from scratch" tutorial which doesn't operate in a sandbox.  For example, you won't be running the RAILSNEW *CMD.

Logging In

All interaction with the sandbox environment is done through an SSH session from your desktop/laptop to PASE on IBM i.  This link describes how to accomplish logging in with SSH along with where to get software if you use Windows.

Below we see a screenshot of logging in and then displaying the working directory (i.e. pwd results in /home/e0001) and listing the working directory contents (i.e. ls results in app1003).  The folder starting with "app..." is the pre-created Rails application.  The reason it is pre-created is so the necessary IBM i database libraries could be created with an admin profile.

Sandbox Log In

The Initial Rails App

The initial Rails application folder and configuration infrastructure exists, including the IBM i database libraries as specified in the config/database.yml file, but the app doesn't yet do anything.  To see what the app currently looks like you can start the Rails server with the following command**.  Your port should be the same as your profile - just substitute an "8" for the "e" (i.e. if your profile is e0001 then use port 8001).

rails server -p8001

**Note you first need to change directory (cd) into the app1003 folder.  The app1003 folder is the root of the Rails app and when you run "rails..." commands from within that folder it then knows which application it should work with.

Below we see the Rails server has successfully started and is waiting for connections.

Rails Server p8001

If we go to the browser we should see the following.  Note the xxx.xxx.xxx.xxx should be replaced with the same server as what you logged in with.

Welcome aboard

Next we will stop the server by going back to the SSH session and selecting Ctrl+C.

List Current Tables

One tool you will find very useful while developing is the Rails Console.  The rails console command will load up and initialize the current application so you can interact with it - for example, get a list of existing database tables as shown below.

List all tables: ActiveRecord::Base.connection.tables
Rails Console Command

As expected, there are currently no tables in library APP1001_D.  We can create new tables by pursuing our first feature of the application.  Type "quit" to exit the Rails Console.

Generate Blog CRUD (Create, Read, Update, Delete)

Next we will create a full scaffold** (aka model, views, controller) for a blog application by issuing the following command from our app root directory.  Every blog has posts so we will create scaffolding for a post.

rails generate scaffold post title:string body:string

Here are the results:
Generate Blog CRUD

This accomplished a variety of things including generating an entire Create/Read/Update/Delete application for us to use from the browser.  Before we bring it up in the browser the following command needs to be run to create our posts table:

rake db:migrate

Now if we display the list of tables again we can see posts exists.

Exist the Rails Console by typing "quit" and then start the server with the following command:

rails s -p8001

Then point your browser to URL http://machine_ip:8001/posts and you should see something similar to the following (note I added a single row to the database so you could see values in the columns)

Posts Example

To take this tutorial further you can follow the directions on this URL starting at the section titled "Another Feature".

Editing Source Code

You will obviously need to edit source code.  Included with PowerRuby is the JOE editor which allows you to edit files server-side and requires nothing to install on your laptop/desktop.  To learn a little about JOE you can go here.