Commit 2eca0707

mo khan <mo@mokhan.ca>
2013-06-22 14:37:05
create tutorial tags controller
1 parent 403967d
Changed files (4)
app/controllers/tutorial_tags_controller.rb
@@ -0,0 +1,8 @@
+class TutorialTagsController < ApplicationController
+  def show
+    @tag = params[:id].downcase.gsub(/ /, '-')
+    @total_tutorials = Tutorial.tagged_with(@tag).count
+    @total_creations = Creation.tagged_with(@tag).count
+    @tutorials = Tutorial.includes(:tags).tagged_with(@tag).page(params[:page]).per(15)
+  end
+end
app/views/tags/show.html.erb
@@ -14,7 +14,7 @@
     <h1><%= @total_creations %> creations tagged <em><%= @tag %></em></h1>
   </div>
   <div class="span3">
-    <p class="pull-right"><a href="/tutorials?tag=<%= @tag %>"><%= @total_tutorials %> tutorials</a> &raquo;</p>
+    <p class="pull-right"><%= link_to "#{@total_tutorials} tutorials", tutorial_tag_path(@tag) %> &raquo;</p>
   </div>
 </div>
 <div id="creations-div" class="row">
app/views/tutorial_tags/show.html.erb
@@ -0,0 +1,45 @@
+<% provide(:title, "#{@tag}") -%>
+<% content_for :javascript do -%>
+<script type="text/javascript">  
+  $(function(){
+    var container = $('#tutorials-div');
+    container.imagesLoaded(function(){
+      container.masonry({ itemSelector : '.span4', isResizable: true });
+    });
+  });
+</script>
+<% end -%>
+<div class="row">
+  <div class="span9">
+    <h1><%= @total_tutorials %> tutorials tagged <em><%= @tag %></em></h1>
+  </div>
+  <div class="span3">
+    <p class="pull-right"><%= link_to "#{@total_creations} creations", tag_path(@tag) %> &raquo;</p>
+  </div>
+</div>
+<div id="tutorials-div" class="row">
+  <div class="span12">
+    <ul class="thumbnails">
+    <% @tutorials.each do |tutorial| %>
+      <div class="span4">
+        <div class="thumbnail">
+          <img src="<%= tutorial.image_url %>" />
+          <div class="caption">
+            <h3><a href="<%= tutorial.url %>" target="_blank"><%= tutorial.heading %></a> <small><%= tutorial.created_at.to_s :foomat %></small></h3>
+            <p>
+            <% tutorial.tags.each do |tag| -%>
+              <a href="/tt/<%= tag.name %>"><span class="label"><%= tag.name %></span></a>
+            <% end -%>
+            </p>
+            <p><%= tutorial.description %></p>
+            <p><a class="btn" href="<%= url_for tutorial %>">View</a></p>
+          </div>
+        </div>
+      </div>
+    <% end %>
+    </ul>
+  </div>
+</div>
+<div class="row">
+  <div class="span12 text-center"> <%= paginate @tutorials %> </div>
+</div>
config/routes.rb
@@ -6,6 +6,7 @@ Cake::Application.routes.draw do
   resources :tutorials do
     get 'page/:page', :action => :index, :on => :collection
   end
+  resources :tutorial_tags, :only => [:show], :path => :tt
 
   # /creations
   resources :creations do