end class Article include DataMapper::Resource # Un module! property :id, Serial property :title, String property :content, Text property :created_at, DateTime end DataMapper.finalize DataMapper.auto_upgrade!
:default, "mysql://localhost/blogue" class Article include DataMapper::Resource property :id, Serial property :title, String property :content, Text property :created_at, DateTime end DataMapper.finalize DataMapper.auto_upgrade! end
haml :index, :layout => :blogue end get "/articles/:id" do @article = Article.get(params[:id]) haml :show, :layout => :blogue end post "/articles" do @article = Article.create(params[:article]) redirect to("/article/#{@article.id}") end
include DataMapper::Resource property :id, Serial property :title, String property :content, Text property :created_at, DateTime end DataMapper.finalize DataMapper.auto_upgrade! end get "/" do @articles = Article.all haml :index, :layout => :blogue end get "/articles/:id" do @article = Article.find(params[:id]) haml :show, :layout => :blogue end post "/articles" do @article = Article.create(params[:article]) redirect to("/article/#{@article.id}") end
get "/" do "Hello world." end run Sinatra::Application $ rackup config.ru WEBrick 1.3.1 ruby 1.9.2 (2011-07-09) WEBrick::HTTPServer#start: pid=69232 port=9292