Skip to content

Instantly share code, notes, and snippets.

@devdatta
Forked from woodie/README.rdoc
Created May 22, 2010 05:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdatta/409811 to your computer and use it in GitHub Desktop.
Save devdatta/409811 to your computer and use it in GitHub Desktop.

Rails 2.3.5 on App Engine (DataMapper)

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.5 calls to rubygems, and now we have it working. Rails 2.3.5 currently spins up several seconds faster than Rails 3, and just a few seconds behind Sinatra.

See the TinyDS version also: gist.github.com/269075

Install the Development Environment

The gems for the development environment include a pre-release appengine-tools gem that provides a pre-release version of jruby-rack.

sudo gem install google-appengine

Install Rails 2.3.5 with required patches

Create a folder for your app

mkdir rails_app; cd rails_app

Download and run the setup script

curl -O http://appengine-jruby.googlecode.com/hg/demos/rails2/rails2_appengine.rb
ruby rails2_appengine.rb

Working with Your Rails App

Start development server

./script/server.sh

Open local console

./script/console.sh

Publish to production

./script/publish.sh

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.

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

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
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment