Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Rails 2.3.5 on App Engine with DataMapper

Rails 2.3.5 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.5 with required patches

Install some gems you'll need

sudo gem install rails -v "2.3.5"
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 rails235_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

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
Copy link

joelcuevas commented May 13, 2010

If you want to use the XML versions of the generated scaffolds, you must install the dm-serializer gem because DataMapper doesn't generates valid XML. Of course, you have to require the gem somewhere before you models are used.

Copy link

huemorgan commented May 14, 2010

if someone needs it i got twitter working on APP ENGIEN using the twitter GEM

  1. see the Gemfile for the gems that were bundled here.
    the gem versions matter, older versions don't support new fixes for GAE
    new versions of the twitter GEM currently has binary extentions also not supported by GAE.
  2. see that you set the right callback url in your twitter account
    it should match the oauth.set_callback_url in the session controller.
  3. used DataMapper for models
  4. built on
  5. some valuable info here about bundeling gems and setting up a new project

Copy link

huemorgan commented May 14, 2010

How can I migrate appengien storage structure using DataMapper
DataMapper.auto_upgrade! - doesn't seem to work?

Copy link

masover commented May 19, 2010

No migration needed for trivial things like adding properties. You have to declare a 'property' in DataMapper so it generates accessors and things, but think of the entities themselves as basically hashes.

If you actually have something you want to change on a global level, that's a bit trickier, and would likely require a bit of task queue trickery if you want to do it on an actual live app.

Copy link

gvt commented Jun 10, 2010

super helpful -- thanks!

Copy link

pedrorolo commented Jul 21, 2010

I am unable to follow these instructions: When I try publish the application, I get a message complaining that there are too many files. 8500 instead of the 3000 limit. Does anyone know how to overcome this problem?

Copy link

pedrorolo commented Jul 21, 2010


Copy link

pedrorolo commented Jul 21, 2010

no... using the 238 version of the script didn't do the trick. I am still getting the following message when I try to publish the app: Applications are limited to 3000 files, you have 8914.
Unable to update app: Applications are limited to 3000 files, you have 8914.
Please see the logs [/tmp/appcfg2041444326558256837.log] for further information.

Copy link

woodie commented Jul 21, 2010

I'm guessing that you have do something bad to the Gemfile

Copy link

masover commented Jul 22, 2010

Maybe run a 'find' on your app directory and post that as a gist somewhere?

Copy link

pedrorolo commented Jul 22, 2010

masover: the files listing can be found here:

woodie: what is the Gemfile? How can I tackle its problems?

By the way: My application is empty: I didn't change anything after having ran script that created the directory structure.

Copy link

millisami commented Nov 7, 2010

How to use the Rails 3.0.1 (latest) with app engine??
Is there any other resource coz I googled and couldn't find the exact for Rails 3.

Copy link

fcoloni commented Dec 20, 2011

I publish the app and recive an Error: INTERNAL_SERVER_ERROR (500)
on local server runs ok

Copy link

imustardsoft commented Jan 19, 2012

I publish the app and recive an Error: INTERNAL_SERVER_ERROR (500)
on local server runs ok

Yes. I have same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment