Skip to content

Instantly share code, notes, and snippets.

@woodie
Created November 11, 2010 00:52
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save woodie/671792 to your computer and use it in GitHub Desktop.
Save woodie/671792 to your computer and use it in GitHub Desktop.
Rails 2.3.10 on App Engine with DataMapper

Rails 2.3.10 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: gist.github.com/gists/269075

Install the Development Environment

One meta-gem provides the development environment

sudo gem install google-appengine

Install Rails 2.3.10 with required patches

Install some gems you’ll need

sudo gem install rails -v "2.3.10"
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 http://appengine-jruby.googlecode.com/hg/demos/rails2/rails2310_appengine.rb
ruby rails2310_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.

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
end
@shrimpy
Copy link

shrimpy commented Dec 7, 2010

The script is not working, have to comment out one line of code

FileUtils.rm public/robots.txt

for windows user, *.sh file under script directory is not usable, so open them as text file, copy the command and type in command prompt will do

@zgohr
Copy link

zgohr commented Jan 12, 2011

Why is this same script provided? To get this to work, "sudo install gem plugin", first. Next, comment out lines 62, 72, and 74. Run the script as shown. The script will create a 2.3.10 directory. Copy the script into this new directory, remove comments from 72 and 74 and run it from there. Another directory named 2.3.10 will be created, and from here your script directory will contain a server executable and you can start rails with the command "./2.3.10/2.3.10/script/server" although I have no idea that this is actually starting the app engine stuff correctly, but it does start the rails server. Does anyone have an updated script that works?

@shrimpy
Copy link

shrimpy commented Jan 12, 2011

@zgohr
Copy link

zgohr commented Jan 12, 2011

Shrimpy, same issue where a config/boot.rb does not exist... 2.3.10/config/boot.rb exists but this is the same issue as I've been having.

@woodie
Copy link
Author

woodie commented Jan 12, 2011

I look forward to suggestions, a rails template or Rakefile to do this in a more portable way

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