-
Notifications
You must be signed in to change notification settings - Fork 1
/
expensives.rb
58 lines (48 loc) · 917 Bytes
/
expensives.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rubygems'
require 'sinatra'
require 'active_record'
require 'active_support'
require 'active_support/all'
$KCODE = 'UTF8'
require 'models/post'
configure do
require 'models/database'
end
# Administração
get '/noticias/nova' do
erb :new
end
post '/noticias' do
@post = Post.new(params[:post])
if @post.save
redirect "/noticias/#{@post.slug}"
end
end
post '/ativar/:id' do
@post = Post.find(params[:id])
@post.active = true
if @post.save
redirect "/noticias/#{@post.slug}"
end
end
post '/desativar/:id' do
@post = Post.find(params[:id])
@post.active = false
if @post.save
redirect "/noticias"
end
end
get '/' do
@posts = Post.all
@issue = 1
erb :index
end
get '/noticias/:slug' do
@post = Post.by_slug(params[:slug]).first
@posts = Post.all
erb :show
end
get '/feed' do
@posts = Post.all(:limit => 10, :order => 'id DESC')
builder :feed
end