-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
40 lines (34 loc) · 840 Bytes
/
app.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
require 'sinatra'
require 'mongo_mapper'
require File.join(File.dirname(__FILE__), '/lib/ten_percent_news')
database_config = {
development: {
host: 'localhost',
port: '27017',
db: 'ten_percent_dev'
},
test: {
host: 'localhost',
port: '27017',
db: 'ten_percent_test'
},
}
db_config = database_config[Sinatra::Application.environment]
configure do
if Sinatra::Application.environment == :production
MongoMapper.setup({'production' => {'uri' => ENV['MONGOHQ_URL']}}, 'production')
else
MongoMapper.connection = Mongo::Connection.new(db_config[:host], db_config[:port])
MongoMapper.database = db_config[:db]
end
end
get '/' do
haml :index, locals: {stories: Story.all}
end
get '/stories/new' do
haml :new
end
post '/stories' do
Story.create!(params[:story])
redirect '/'
end