Skip to content

Instantly share code, notes, and snippets.

@lantins
Created May 20, 2009 05:07
Show Gist options
  • Select an option

  • Save lantins/114627 to your computer and use it in GitHub Desktop.

Select an option

Save lantins/114627 to your computer and use it in GitHub Desktop.
require "rubygems"
require "sinatra"
require "dm-core"
# get the database rolling.
DataMapper.setup(:default, :adapter => "sqlite3", :database => "test.sqlite3")
class Account
include DataMapper::Resource
storage_names[:default] = "accounts"
property :id, Integer, :serial => true
property :name, String, :length => 128
property :email, String, :length => 128
property :type, String, :length => 128
end
#Account.auto_migrate!
#luke = Account.create(:name => "Luke", :email => "[email protected]", :type => "normal")
# show the form.
get "/" do
@account = Account.first()
erb :index
end
# update our form.
post "/" do
@account = Account.first()
@account.update_attributes(params[:account])
redirect "/"
end
__END__
@@ layout
<html>
<body>
<%= yield %>
</body>
</html>
@@ index
<form action="/" method="POST">
<input type="text" name="account[name]" value="<%= @account.name %>">
<input type="text" name="account[email]" value="<%= @account.email %>">
<select name="account[type]" size="1">
<option value="normal"<% if @account.type == "normal" %> selected<% end %>>normal</option>
<option value="admin"<% if @account.type == "admin" %> selected<% end %>>admin</option>
</select>
<input type="submit" value="Save Changes">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment