Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

new: posted date

  • Loading branch information...
commit 73a932eed642fc285f23a7c7e04eb29e11ce01b4 1 parent f9bb0ea
@yhara authored
Showing with 15 additions and 2 deletions.
  1. +8 −1 start.rb
  2. +7 −1 views/index.haml
View
9 start.rb
@@ -6,15 +6,21 @@
DB = Sequel.sqlite("comments.db")
class Comments < Sequel::Model
set_schema do
+ primary_key :id
string :name
string :title
text :message
+ timestamp :posted_date
+ end
+
+ def date
+ self.posted_date.strftime("%Y-%m-%d %H:%M:%S")
end
end
Comments.create_table unless Comments.table_exists?
get '/' do
- @comments = Comments.all
+ @comments = Comments.order_by(:posted_date.desc)
haml :index
end
@@ -23,6 +29,7 @@ class Comments < Sequel::Model
:name => request[:name],
:title => request[:title],
:message => request[:message],
+ :posted_date => Time.now,
})
redirect '/'
View
8 views/index.haml
@@ -24,7 +24,13 @@
- @comments.each do |comment|
.comment
- %h2== #{comment.title} (by #{comment.name})
+ %h2
+ %span.title= comment.title
+ %span.name== (#{comment.name})
+
+ .date
+ = comment.date
+
.message
= comment.message
Please sign in to comment.
Something went wrong with that request. Please try again.