
Untitled
By: a guest on
Jun 26th, 2012 | syntax:
None | size: 1.10 KB | hits: 7 | expires: Never
# app.rb
require 'sinatra'
require 'sinatra/sequel'
require 'sass'
require 'logger'
require 'rack-flash'
enable :sessions
use Rack::Flash
set :database, 'mysql://root:root@localhost/todo_app'
puts "the posts table doesn't exist" if !database.table_exists?('posts')
migration "create the posts table" do
database.create_table :posts do
primary_key :id
Integer :priority
String :title, :text => true
timestamp :created_at, :null => false
index :priority, :unique => true
end
end
class Post < Sequel::Model
end
get '/' do
@posts = Post.all
@notice = flash[:notice]
erb :index
end
post '/create' do
if !params[:title].empty?
Post.insert(:title => params[:title])
flash[:notice] = "Todo Created"
else
flash[:notice] = "Todo needs title"
end
redirect '/'
end
get '/sortList' do
params.each do |key, value|
puts key+": "+value
end
end
get '/:id/delete' do
if params[:id]
@post = Post[params[:id]].delete
flash[:notice] = "Todo deleted"
else
end
redirect '/'
end
get '/style.css' do
scss :style
end