Skip to content

Commit

Permalink
Comment counts
Browse files Browse the repository at this point in the history
  • Loading branch information
luontola committed Feb 23, 2018
1 parent 413c47d commit 1ccc7b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion app.rb
Expand Up @@ -29,7 +29,11 @@ class Comment

get '/pictures.html' do
@title = "Lovely Pictures"
@picture_urls = picture_urls
@pictures = picture_urls.map { |url| {
:picture_url => url,
:page_url => url.sub(/\.\w+$/, '.html'),
:comments => Comment.count(:picture => File.basename(url, '.*'))
}}
erb :pictures
end

Expand Down
6 changes: 3 additions & 3 deletions views/pictures.erb
@@ -1,10 +1,10 @@
<h1>Pictures I like</h1>

<div class="album">
<% for url in @picture_urls %>
<% for picture in @pictures %>
<div class="album-caption">
<a href="<%= url.sub(/\.\w+$/, '.html') %>"><img class="album-photo" src="<%= url %>"></a>
<br>0 comments
<a href="<%= picture[:page_url] %>"><img class="album-photo" src="<%= picture[:picture_url] %>"></a>
<br><%= picture[:comments] %> comments
</div>
<% end %>
</div>

0 comments on commit 1ccc7b0

Please sign in to comment.