Skip to content

Commit f545437

Browse files
committed
Messages display with markdown, and have a nicer interface.
Messages didn't have the title for a while... I'm going to have to make real layouts soon. They also have a handy reply button, and are in reverse chronological order.
1 parent 3a819c0 commit f545437

4 files changed

Lines changed: 69 additions & 14 deletions

File tree

controllers/messages.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
#this is the page where you can see your messages
3131
get "/messages" do
3232
require_login!
33-
@messages = Message.all({"recipient" => current_user.username})
33+
@messages = Message.all({"recipient" => current_user.username}).sort do |a, b|
34+
b.created_at <=> a.created_at
35+
end
3436
haml :"messages/index"
3537
end
3638

models/message.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Message
1212
#this is the username of the person who sent the message
1313
key :sender, String
1414

15+
timestamps!
16+
1517
after_create :send_notification
1618

1719
private

views/messages/index.haml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
%ul
2-
- @messages.each do |message|
3-
%li From: #{message.sender}
4-
%li Message: #{message.body}
1+
.span-9
2+
%img{:height => "64", :src => "/images/logo.png", :style => "float:left"}/
3+
%p.body{:style => "padding-top:20px;padding-left:80px"} Hackety Hack
4+
- if logged_in?
5+
.span-6.prepend-3.last
6+
%ul
7+
%li{:style => "display:inline"}
8+
%a{:href => "/download"} Download
9+
|
10+
%li{:style => "display:inline"}
11+
%a{:href => "/hackers/#{current_user.username.to_slug}"} My Page
12+
|
13+
%li{:style => "display:inline"}
14+
%a{:href => "/logout"} Log out
15+
- else
16+
.span-4.prepend-5.last
17+
%ul
18+
%li{:style => "display:inline"}
19+
%a{:href => "/download"} Download
20+
|
21+
%li{:style => "display:inline"}
22+
%a{:href => "/login"} Log in
23+
.span-18.last
24+
%h1 Your Messages
25+
%ul
26+
- @messages.each do |message|
27+
%li{:style => "list-style:none"}
28+
%h2 From: #{message.sender}
29+
:markdown
30+
#{message.body}
31+
%a{:href => "/messages/new/to/#{message.sender}"} (reply)
32+
%hr
533

views/messages/new.haml

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,33 @@
1-
%h2 Sending a message to #{@username}
2-
%form{:action => "/messages", :method => "POST"}
3-
%input{:type => "hidden", :id => "message_recipient", :name => "message[recipient]", :value => @username}
4-
%br/
5-
%label{:for => "message_body" } Message text:
6-
%br/
7-
%textarea{:id => "message_body", :name => "message[body]"}
8-
%br/
9-
%input{:type => "submit", :value => "Send message", :class => "button"}
1+
.span-9
2+
%img{:height => "64", :src => "/images/logo.png", :style => "float:left"}/
3+
%p.body{:style => "padding-top:20px;padding-left:80px"} Hackety Hack
4+
- if logged_in?
5+
.span-6.prepend-3.last
6+
%ul
7+
%li{:style => "display:inline"}
8+
%a{:href => "/download"} Download
9+
|
10+
%li{:style => "display:inline"}
11+
%a{:href => "/hackers/#{current_user.username.to_slug}"} My Page
12+
|
13+
%li{:style => "display:inline"}
14+
%a{:href => "/logout"} Log out
15+
- else
16+
.span-4.prepend-5.last
17+
%ul
18+
%li{:style => "display:inline"}
19+
%a{:href => "/download"} Download
20+
|
21+
%li{:style => "display:inline"}
22+
%a{:href => "/login"} Log in
23+
.span-18.last
24+
%h2 Sending a message to #{@username}
25+
%form{:action => "/messages", :method => "POST"}
26+
%input{:type => "hidden", :id => "message_recipient", :name => "message[recipient]", :value => @username}
27+
%br/
28+
%label{:for => "message_body" } Message text:
29+
%br/
30+
%textarea{:id => "message_body", :name => "message[body]"}
31+
%br/
32+
%input{:type => "submit", :value => "Send message", :class => "button"}
1033

0 commit comments

Comments
 (0)