Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

views

  • Loading branch information...
commit 9bf84b5a71df9e5a17536589e28b3ee905bfddd3 1 parent d856506
@jweiss jweiss authored
View
3  app/controllers/photos_controller.rb
@@ -1,6 +1,7 @@
class PhotosController < ApplicationController
def index
- @photos = Photo.all
+ @photos = Photo.find(:all, :include => :ratings)
+ @top_photos = Photo.find(:all, :limit => 3, :joins => :ratings, :group => 'ratings.photo_id', :having => 'ratings.value > 3')
respond_to do |format|
format.html # index.html.erb
View
21 app/views/photos/_photos.html.erb
@@ -0,0 +1,21 @@
+<table>
+ <tr>
+ <th>Name</th>
+ <th>Preview</th>
+ <th>#Ratings</th>
+ <th>Average</th>
+ </tr>
+
+<% photos.each do |photo| %>
+ <tr>
+ <td><%= link_to h(photo.name), photo %></td>
+ <td>
+ <a href="<%= photo_url(photo) %>">
+ <%= image_tag photo.body.url, :width => 60 %>
+ </a>
+ </td>
+ <td><%= photo.ratings.count %></td>
+ <td><%= photo.ratings.all.map{|x| x.value.to_i}.sum / photo.ratings.count.to_f %></td>
+ </tr>
+<% end %>
+</table>
View
33 app/views/photos/index.html.erb
@@ -1,25 +1,14 @@
-<h1>Listing photos</h1>
-
-<table>
- <tr>
- <th>Name</th>
- <th>Preview</th>
- <th>#Ratings</th>
- <th>Average</th>
- </tr>
-
-<% @photos.each do |photo| %>
- <tr>
- <td><%=h photo.name %></td>
- <td><%= image_tag photo.body.url, :width => 60 %></td>
- <td><%= photo.ratings.count %></td>
- <td><%= photo.ratings.all.map{|x| x.value.to_i}.sum / photo.ratings.count.to_f %></td>
- <td><%= link_to 'Show', photo %></td>
- <td><%= link_to 'Edit', edit_photo_path(photo) %></td>
- <td><%= link_to 'Destroy', photo, :confirm => 'Are you sure?', :method => :delete %></td>
- </tr>
-<% end %>
-</table>
+
+<h1>Top photos</h1>
+
+ <%= render :partial => 'photos', :locals => {:photos => @top_photos} %>
+
+<br />
+
+
+<h1>All photos</h1>
+
+ <%= render :partial => 'photos', :locals => {:photos => @photos} %>
<br />
View
2  app/views/photos/show.html.erb
@@ -16,8 +16,10 @@
<%= link_to 'Edit', edit_photo_path(@photo) %> |
+<%= link_to 'Destroy', @photo, :confirm => 'Are you sure?', :method => :delete %> |
<%= link_to 'Back', photos_path %>
+
<% content_for(:page_header) do %>
<script type="text/javascript" src="/javascripts/jvote/jVote.js"></script>
<script type="text/javascript">
Please sign in to comment.
Something went wrong with that request. Please try again.