Cloud Foundry Now Supports the Rails Console

February 8, 2012 Jennifer Hickey

featured-cf-genericRuby and Rails developers can now remotely access the popular rails console using the Cloud Foundry command line tool (VMC). This new feature enables inspection of the Cloud Foundry Runtime App environment, troubleshooting application issues in runtime, and even the ability to modify data “on the fly” for one-off admin tasks. Using the new vmc rails-console command, developers can target any Cloud Foundry instance, including the upcoming release of Micro Cloud Foundry.

Getting Started

First, install or update your Cloud Foundry command line tool (‘VMC’) to the latest preview version using the following command:

gem install vmc --pre

You can verify that you got the right version using:

vmc -v

which should show the version to be 0.3.16.beta.3 or higher.

Next, push or update a Rails app using vmc push.

To access the console, run:

vmc rails-console appname

That’s all there is to it! Read on for a more detailed example…

Using the Rails Console

Let’s get started by deploying a Rails application to Cloud Foundry. We’ll use Enki, an open source blog engine. I’ll use the cloudfoundry-samples fork, where I’ve added the mysql2 gem to enki’s Gemfile. Now I’m ready to push to Cloud Foundry:

mycomp:enki$ vmc push mynewblog
Would you like to deploy from the current directory? [Yn]:
Application Deployed URL []:
Detected a Rails Application, is this correct? [Yn]:
Memory Reservation ("64M", "128M", "256M", "512M", "1G") ["256M"]:
Creating Application: OK
Create services to bind to 'mynewblog'? [yN]: y
1: mongodb
2: mysql
3: postgresql
4: rabbitmq
5: redis
What kind of service?: 2
Specify the name of the service [mysql-8f1d2]:
Creating Application: OK
Creating Service [mysql-8f1d2]: OK
Binding Service [mysql-8f1d2]: OK
Uploading Application:
  Checking for available resources: OK
  Processing resources: OK
  Packing application: OK
  Uploading (20M): OK
Push Status: OK
Staging Application: OK
Starting Application: OK

Looks like the app deployed successfully. I saved the manifest generated from this vmc output, so you can do just a simple “vmc push” with the application name and URL after cloning the sample.

I’ll make my first blog post about this new Rails Console support and wait for the comments to start rolling in…

Unfortunately, it looks like I have a nasty comment from Joe that needs deleting. Let’s fire up the Rails Console through vmc to easily get rid of that comment. The vmc rails-console command can be run from any directory.

mycomp:enki$ vmc rails-console mynewblog
Deploying tunnel application 'caldecott'.
Uploading Application:
  Checking for available resources: OK
  Packing application: OK
  Uploading (1K): OK
Push Status: OK
Staging Application 'caldecott': OK
Starting Application 'caldecott': OK
Connecting to 'mynewblog' console: OK


Since this is the first time I’ve run Rails Console, vmc will deploy the caldecott application for me, which helps tunnel communication to my remote Rails application. After that, it fires up the console and waits for input.

irb():001:0> @comment = Comment.find_by_author("Joe")
#<Comment id: 7, post_id: 1, author: "Joe", body: "I have something real...">
irb():002:0> @comment.delete
#<Comment id: 7, post_id: 1, author: "Joe", body: "I have something real...">
irb():003:0> @comment = Comment.find_by_author("Joe")
irb():004:0> exit

In this console session, I use Comment.find_by_author to find Joe’s comment, delete the comment, and then check to ensure that Joe’s comment has been removed. Let’s refresh the web page and see that it’s gone:

This is just one small example of what can be done with Rails Console. I could use it for all sorts of diagnostics as well, such as perusing the database, running ruby commands to inspect state, or interacting with controller methods to check responsiveness. For more information, check out the Rails Console documentation or this handy screencast from RailsCasts.

Enabling the Rails Console

The console will automatically be available when you push any Rails application. If you already have a Rails application deployed to Cloud Foundry, you will need to update or redeploy your app to stage the console support.

What are you waiting for? Go try it out!

Ready to start interacting with your Rails app on Cloud Foundry? Make sure to update to the latest vmc gem, and you should be ready to give it a whirl. Please feel free to direct any suggestions or feedback to the support forums!

– Jennifer Hickey
The Cloud Foundry Team

Don’t have a Cloud Foundry account yet? Sign up for free today

About the Author



Ben Adida, Mozilla’s Director of Identity, talks about BrowserID, “an experimental new way of signing into ...

IntelliJ Modules in Rubymine
IntelliJ Modules in Rubymine

IntelliJ has a feature called modules: "a functional unit which you can compile, run, test and debug indepe...

SpringOne 2021

Register Now