17. Define schema in the code
instead of the database
http://datamapper.org
18. class Post
include DataMapper::Resource
property :id, Serial
property :title, String
property :body, Text
property :created_at, DateTime
has n, :comments
end
DataMapper.auto_upgrade!
Post.first(:title => quot;First Postquot;)
19. Access a database with
just hashes - or map
models
http://sequel.rubyforge.org
22. ActionController::Routing::Routes.draw do |map|
map.resource :posts
end
class PostsController < ApplicationController
def create
@post = Post.create! params
redirect_to(@post)
end
def show
@post = Post.find(params[:id])
end
end
25. Merb::Router.prepare do |router|
resource :posts
end
class Posts < Merb::Controller
def create
@post = Post.create params
redirect(url(:post, @post))
end
def show
@post = Post.find(params[:id])
display @post
end
end
29. require 'rubygems'
require 'sinatra'
require 'lib/posts'
post '/posts'
post = Post.create! params
redirect quot;/posts/#{post.id}quot;
end
get '/posts/:id' do
@post = Post.find(params[:id])
erb :post
end
38. describe Post do
it quot;generates a url slug from the titlequot; do
post = Post.new :title => quot;First Postquot;
post.slug.should == quot;first_postquot;
end
it quot;drops punctuation from the url slugquot; do
post = Post.new :title => quot;My Post!quot;
post.slug.should == quot;my_postquot;
end
end
39. $ rake spec:doc
Post
- generates a url slug from the title
- drops punctuation from the url slug