Skip to content

Instantly share code, notes, and snippets.

@ribrdb
Created October 20, 2009 01:35
Show Gist options
  • Select an option

  • Save ribrdb/213906 to your computer and use it in GitHub Desktop.

Select an option

Save ribrdb/213906 to your computer and use it in GitHub Desktop.
require 'appengine-rack'
require 'appengine-rack/java'
# TODO: Fill in your app id
AppEngine::Rack.app.configure(:application => '', :version => '1')
run JavaServlet.new('DubyApp')
import javax.servlet.http.HttpServlet
import com.google.appengine.ext.duby.db.Model
class Post < Model
def initialize; end
property title, String
property body, Text
end
class DubyApp < HttpServlet
def_edb(list, 'template.eduby.html')
def doGet(request, response)
returns :void
@posts = Post.all.run
response.getWriter.write(list)
end
def doPost(request, response)
post = Post.new
post.title = request.getParameter('title')
post.body = Text.new(request.getParameter('body'))
post.save
doGet(request, response)
end
end
<title>Posts</title>
<body>
<h1>All Posts:</h1>
<% i = 0; while i < @posts.length %>
<h2><%= @posts[i].title %></h2>
<p><%= @posts[i].body.getValue %></p>
<% i += 1;end %>
<hr>
<h1>New Post:</h1>
<form method=post>
Title: <input type=text name=title><br>
Body: <textarea name=body></textarea><br>
<input type=submit>
</form>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment