Skip to content

Instantly share code, notes, and snippets.

@esparkman
Created February 1, 2013 02:26
Show Gist options
  • Save esparkman/4688692 to your computer and use it in GitHub Desktop.
Save esparkman/4688692 to your computer and use it in GitHub Desktop.
%h1
= @song.title
%p
Release Date: #{@song.released_on.strftime("%e %B %Y") if @song.released_on}
%p
Length: #{@song.length/60} minutes #{@song.length%60} seconds
%pre
= @song.lyrics
%p
%a{href: "/songs"} Back to Songs Index
%p
%a{href: "/songs/#{@song.id}/edit"} Edit this Song
%form{action: "/songs/#{@song.id}", method: "POST"}
%input{type: "hidden", name: "_method", value: "DELETE"}
%input{type: "submit", value: "Delete This Song"}
require 'dm-core'
require 'dm-migrations'
DataMapper.setup(:default, "postgres://localhost/songsbysinatra")
DataMapper.finalize.auto_upgrade!
class Song
include DataMapper::Resource
property :id, Serial
property :title, String
property :lyrics, Text
property :length, Integer
property :released_on, Date
end
DataMapper.finalize
get '/songs' do
@songs = Song.all
haml :songs
end
get '/songs/:id' do
@song = Song.get(params[:id])
haml :show_song
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment