-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
53 lines (43 loc) · 1.02 KB
/
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
41
42
43
44
45
46
47
48
49
50
51
52
53
require "data_mapper"
require "dm-core"
require "dm-migrations"
require "dm-sqlite-adapter"
require "dm-timestamps"
# require "pry"
# config = YAML.load_file(File.join(Dir.pwd,'config.yml'))
configure do
DataMapper::setup(:default, File.join('sqlite3://', Dir.pwd, 'development.db'))
# DataMapper::setup(:default, 'sqlite3:///home/susan/ruby/typing_tutor/development.db')
end
class ContentBlock
include DataMapper::Resource
property :id, Serial
property :content, Text
property :created_at, DateTime
property :updated_at, DateTime
def self.random_content
all.sample
end
end
# ContentBlock.auto_migrate!
configure :development do
DataMapper.finalize
DataMapper.auto_upgrade!
end
get '/' do
@title = 'Content Blocks'
@content = ContentBlock.random_content
haml :index
end
get '/add_content' do
haml :add_content_form
end
post '/add_content' do
content_block = ContentBlock.new(params)
if content_block.save
@message = "sahi"
else
@message = "Not good"
end
haml :add_content_create
end