Commit 52ee69e0

mo k <mo@mokhan.ca>
2012-11-02 04:51:12
add query object to lookup all creations.
1 parent aec1677
app/controllers/application_controller.rb
@@ -1,7 +1,7 @@
 class ApplicationController < ActionController::Base
   protect_from_forgery
 
-  def command_for(command)
-    command.new(current_user)
+  def resolve(target)
+    target.new(current_user)
   end
 end
app/controllers/comments_controller.rb
@@ -6,7 +6,7 @@ class CommentsController < ApplicationController
   end
 
   def create
-    comment = command_for(CommentOnCreationCommand).run(params)
+    comment = resolve(CommentOnCreationCommand).run(params)
     redirect_to comment.commentable, :notice => 'Nice Comment!'
   end
 end
app/controllers/creations_controller.rb
@@ -2,7 +2,7 @@ class CreationsController < ApplicationController
   before_filter :authenticate_user!, :except => [:show, :index]
   # GET /creations
   def index
-    @creations = Creation.where(:is_restricted => false, :is_published => true).page(params[:page]).per(16)
+    @creations = resolve(FindAllCreationsQuery).fetch(params)
   end
 
   # GET /creations/1
app/helpers/creations_helper.rb
@@ -1,7 +1,6 @@
 module CreationsHelper
   def short_name(creation, length)
     if( creation.name.length > length)
-      #creation.name.split(//).first(length).join('') + '...'
       creation.name[0...length] + '...'
     else
       creation.name
app/helpers/tutorials_helper.rb
@@ -1,2 +0,0 @@
-module TutorialsHelper
-end
app/models/avatar.rb
@@ -1,5 +1,4 @@
 class Avatar < ActiveRecord::Base
   belongs_to :user
   mount_uploader :avatar, AvatarUploader
-  after_save :enqueue
 end
app/services/comment_on_creation_command.rb
@@ -2,8 +2,8 @@ class CommentOnCreationCommand
   def initialize(user)
     @current_user = user
   end
-  def run(params)
-    comment = @current_user.comment_on(Creation.find(params[:creation_id]), params[:comment][:body])
+  def run(message)
+    comment = @current_user.comment_on(Creation.find(message[:creation_id]), message[:comment][:body])
     comment.save
     comment
   end
app/services/find_all_creations_query.rb
@@ -0,0 +1,8 @@
+class FindAllCreationsQuery
+  def initialize(user)
+    @user = user
+  end
+  def fetch(params)
+    Creation.where(:is_restricted => false, :is_published => true).page(params[:page]).per(16)
+  end
+end
app/views/creations/index.html.erb
@@ -1,8 +1,10 @@
 <% provide(:description, "CakeSide is a free site to share your cake creations and ideas with other cake fanatics like yourself") -%>
+<% content_for(:page_header) do %>
+  <h1>Recently added cake creations</h1>
+<% end %>
 <% unless user_signed_in?  -%>
   <div class="row">
     <div class="span6">
-      <h1>Recently added cake creations</h1>
       <div id="slideshow" class="carousel slide">
         <div class="carousel-inner">
           <% @creations.each_with_index do |creation, index| %>