Commit 5c69c38d

mo khan <mo@mokhan.ca>
2013-06-16 16:12:57
eager fetch tags on the tags page
1 parent 2ac8eb2
Changed files (2)
app
app/controllers/tags_controller.rb
@@ -1,7 +1,7 @@
 class TagsController < ApplicationController
   def show
     @tag = params[:id]
-    @tutorials = Tutorial.tagged_with([@tag])
-    @creations = Creation.tagged_with([@tag])
+    @tutorials = Tutorial.includes(:tags).tagged_with([@tag])
+    @creations = Creation.includes([:tags, :user]).tagged_with([@tag])
   end
 end
app/views/tags/show.html.erb
@@ -11,6 +11,7 @@
 <% end -%>
 <% content_for :page_header do -%>
   <h1>Tagged <em><%= @tag %></em></h1>
+  <h2><%= @creations.count %> creations and <%= @tutorials.count %> tutorials</h2>
 <% end -%>
 <div id="tutorials-div" class="row">
   <div class="span12">
@@ -20,7 +21,7 @@
         <div class="thumbnail">
           <a href="<%= url_for tutorial %>"><img src="<%= tutorial.image_url %>" /></a>
           <div class="caption">
-            <h3><a href="<%= tutorial.url %>" target="_blank"><%= tutorial.heading %></a> <small><%= tutorial.created_at.to_s :foomat %></small></h3>
+            <h3><a href="<%= tutorial.url %>" target="_blank"><%= tutorial.heading %></a></h3>
             <p>
             <% tutorial.tags.each do |tag| -%>
               <a href="/tags/<%= tag.name %>"><span class="label"><%= tag.name %></span></a>