Export to GitHub

appengine-jruby - GettingStarted.wiki


If you have issues please see the Google Group.

Hello, World

Use standard Ruby, the tools automatically use JRuby when necessary.

```

Install the google-appengine gem

sudo gem install google-appengine bundle

Create a simple app

appcfg.rb generate_app hello

Start development server

dev_appserver.rb hello ```

Building a guestbook using Sinatra

```

assign gems to your application

cat >Gemfile <

Critical default settings:

disable_system_gems disable_rubygems bundle_path ".gems/bundler_gems"

List gems to bundle here:

gem "dm-appengine" gem "sinatra" EOF

Update config.ru to use Sinatra

cat >config.ru <

Now open a file called 'guestbook.rb'

``` require 'sinatra' require 'dm-core'

Configure DataMapper to use the App Engine datastore

DataMapper.setup(:default, "appengine://auto")

Create your model class

class Shout include DataMapper::Resource

property :id, Serial property :message, Text end

Make sure our template can use <%=h

helpers do include Rack::Utils alias_method :h, :escape_html end

get '/' do # Just list all the shouts @shouts = Shout.all erb :index end

post '/' do # Create a new shout and redirect back to the list. shout = Shout.create(:message => params[:message]) redirect '/' end

END

@@ index Shoutout!

Shoutout!

<form method=post>
  <textarea name="message" rows="3"></textarea>
  <input type=submit value=Shout>
</form>

<% @shouts.each do |shout| %>
<p>Someone wrote, <q><%=h shout.message %></q></p>
<% end %>

<div style="position: absolute; bottom: 20px; right: 20px;">
<img src="/images/appengine.gif"></div>

```

Uploading your app

```

Create an application-id at appspot.com:

http://appengine.google.com/start/createapp

Replace the application-id in app.yaml

application your-app-id

Upload to App Engine

appcfg.rb update .

It should now be running at http://your-app-id.appspot.com

```