Skip to content

Instantly share code, notes, and snippets.

@woodie
Created January 5, 2010 02:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save woodie/269075 to your computer and use it in GitHub Desktop.
Save woodie/269075 to your computer and use it in GitHub Desktop.
Rails 2.3.10 on App Engine with TinyDS

Rails 2.3.10 on App Engine (TinyDS)

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 DataMapper version also: gist.github.com/671792

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_tiny_ds
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 rails239_appengine.rb tiny_ds

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 article title:string summary:text url:string \
pages:integer -f --skip-migration

Generate a model for TinyDS

./script/generate td_model article title:string summary:text url:string \
pages:integer -f

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

class Article < TinyDS::Base
property :title, :string
property :summary, :text
property :url, :string
property :pages, :integer
property :created_at, :time
property :updated_at, :time
end
@flockonus
Copy link

First of all, congratulations, it is a very neat tutorial!

Problem1:

fps ~/workspace3/jrails_app $ ruby rails2310_appengine.rb tiny_ds                                                                                                
=> Bundling gems                                                                                                                                                 
Calculating dependencies...                                                                                                                                      
Updating source: http://gems.rubyforge.org                                                                                                                       
/usr/lib/ruby/gems/1.8/gems/bundler08-0.8.5/lib/bundler08/resolver.rb:115:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010.  Use #requirement                                                                                                                              
No compatible versions could be found for required dependencies:                                                                                                 
    Conflict on: "rails":                                                                                                                                        
    * rails (2.3.10) activated by rails (= 2.3.10, runtime)                                                                                                      
    * rails (= 2.3.5, runtime) required by rails_tiny_ds (>= 0, runtime)                                                                                         
    All possible versions of origin requirements conflict.                                                                                                       
/usr/lib/ruby/1.8/fileutils.rb:1298:in `unlink': No such file or directory - public/robots.txt (Errno::ENOENT)                                                   
        from /usr/lib/ruby/1.8/fileutils.rb:1298:in `remove_file'                                                                                                
        from /usr/lib/ruby/1.8/fileutils.rb:1303:in `platform_support'                                                                                           
        from /usr/lib/ruby/1.8/fileutils.rb:1297:in `remove_file'                                                                                                
        from /usr/lib/ruby/1.8/fileutils.rb:771:in `remove_file'                                                                                                 
        from /usr/lib/ruby/1.8/fileutils.rb:549:in `rm'                                                                                                          
        from /usr/lib/ruby/1.8/fileutils.rb:548:in `each'                                                                                                        
        from /usr/lib/ruby/1.8/fileutils.rb:548:in `rm'                                                                                                          
        from rails2310_appengine.rb:62  

To patch, line 62:
FileUtils.rm( 'public/robots.txt') rescue true
Successfully created App

Problem2:

fps ~/workspace3/jrails_app $ ./script/server.sh
=> Bundling gems                                                                                                                                                 
Calculating dependencies...                                                                                                                                      
Updating source: http://gems.rubyforge.org                                                                                                                       
/usr/lib/ruby/gems/1.8/gems/bundler08-0.8.5/lib/bundler08/resolver.rb:115:Warning: Gem::Dependency#version_requirements is deprecated and will be removed on or after August 2010.  Use #requirement                                                                                                                              
No compatible versions could be found for required dependencies:                                                                                                 
    Conflict on: "rails":                                                                                                                                        
    * rails (2.3.10) activated by rails (= 2.3.10, runtime)                                                                                                      
    * rails (= 2.3.5, runtime) required by rails_tiny_ds (>= 0, runtime)                                                                                         
    All possible versions of origin requirements conflict. 

Monkey patched, gemfile.rb from line line 6:
# List gems to bundle here:
gem 'rails_tiny_ds', '0.0.2.1'
gem 'rails_appengine'
gem 'rails', '2.3.8'

If there is a source to get rails_tiny_ds working with rails 2.3.10, please share

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