Last active

Rails 2.3.8 on App Engine with DataMapper

  • Download Gist

Rails 2.3.8 on App Engine (DataMapper)

Do not use rvm (or install and run from JRuby). The google-appengine gem must install into your system MRI. The appengine-sdk gem includes a complete Java app server. We bootstrap Java from MRI, then your app runs inside a servlet container (with access to all the APIs) using the version of JRuby installed into each app.

We assumed Rails 2 would never work without rubygems, and we committed to gem bunlder for JRuby on App Engine, so we were waiting for Rails 3. Fortunately, Takeru Sasaki was able to patch the Rails 2.3.x calls to rubygems, and now we have it working. Rails 2.3.x currently spins up several seconds faster than Rails 3, and just a few seconds behind Sinatra.

See the TInyDS version also:

Install the Development Environment

One meta-gem provides the development environment

sudo gem install google-appengine

Install Rails 2.3.8 with required patches

Install some gems you'll need

sudo gem install rails -v "2.3.8"
sudo gem install rails_dm_datastore
sudo gem install activerecord-nulldb-adapter

Create a folder for your app

mkdir rails_app; cd rails_app

Download and run the setup script

curl -O
ruby rails238_appengine.rb

Working with Your Rails App

Start development server


Open local console


Publish to production


Support for generators

We disable rubygems in the development environment, and the generators from Rails 2 perform various Gem dependency checks that are too difficult to patch, so we run the generators from the MRI. We also use Josh Moore's rails_dm_datastore integration plugin.

Generate a restful controller and add it to config/routes.rb

./script/generate scaffold contact title:string summary:text \
birthday:date url:string address:string phone:string -f --skip-migration

Generate a model for DataMapper

./script/generate dd_model contact title:string summary:text \
birthday:date url:link address:postal_address phone:phone_number -f

You’ve created a RESTful controller, and a DataMapper model

1 2 3 4 5 6 7 8 9 10 11 12 13
class Contact
include DataMapper::Resource
storage_names[:default] = "Contact"
property :id, Serial
property :title, String, :required => true, :length => 500
property :summary, Text, :required => true, :lazy => false
property :birthday, Date, :required => true
property :url, Link, :required => true
property :address, PostalAddress, :required => true
property :phone, PhoneNumber, :required => true
timestamps :at

When I try to publish my application - which currently consists only on the files generated by the script given above, I get an error complaining that my application exceeds the 3000 files limit? Is there any way to go around this problem? Thanks in Advance.

I follow the guide and it works ok in development server and production but i couldn't work with models in development console (./script/

irb(main):001:0> Contact.all
NativeException: java.lang.NullPointerException: No API environment is registered for this thread.
from com/google/appengine/api/datastore/ getCurrentAppId'
from com/google/appengine/api/datastore/

Any solution?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.