This repository was archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.rb
More file actions
77 lines (69 loc) · 1.37 KB
/
Copy pathapplication.rb
File metadata and controls
77 lines (69 loc) · 1.37 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
require 'sinatra/base'
require 'mongoid'
require 'mongoid_smart_tags'
class Blog < Sinatra::Base
set :root, File.dirname(__FILE__)
class Post
# includes
include Mongoid::Document
include Mongoid::SmartTags
include Mongoid::Timestamps
# schema definition
field :disable_comments, type: Boolean, default: false
field :content
field :title
# indexes
index({ title: 1 }, { unique: true })
# relationships
embeds_many :comments
# validations
validates :content, presence: true
validates :title, presence: true
# standard methods
# custom methods
end
class Comment
# includes
include Mongoid::Document
include Mongoid::Timestamps
# schema definition
field :author
field :content
field :email_address
# indexes
index({ title: 1 }, { unique: true })
# relationships
embedded_in :post
# validations
validates :author, presence: true
validates :content, presence: true
validates :email_address, format: { with: // }, presence: true
# standard methods
# custom methods
end
class User
# custom methods
def self.login()
end
end
get '/' do
@posts = Post.all
erb :index
end
get '/post' do
@post = Post.new
erb :new
end
get '/reading' do
@post = Post.find(params[:id])
erb :show
end
post '/post' do
@post = Post.new(params[:post])
if @post.save
redirect '/'
else
redirect '/post'
end
end
end