diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index 9b96659..892e096 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,4 +1,6 @@ class CommentsController < ApplicationController + COMMENTS_PER_PAGE = 20 + before_filter :require_logged_in_user_or_400, :only => [ :create, :preview, :upvote, :downvote, :unvote ] @@ -188,8 +190,18 @@ class CommentsController < ApplicationController @heading = @title = "Newest Comments" @cur_url = "/comments" - @comments = Comment.find(:all, :conditions => "is_deleted = 0", - :order => "created_at DESC", :limit => 20, :include => [ :user, :story ]) + @page = 1 + if params[:page].to_i > 0 + @page = params[:page].to_i + end + + @comments = Comment.find( + :all, + :conditions => "is_deleted = 0 AND is_moderated = 0", + :order => "created_at DESC", + :offset => ((@page - 1) * COMMENTS_PER_PAGE), + :limit => COMMENTS_PER_PAGE, + :include => [ :user, :story ]) if @user @votes = Vote.comment_votes_by_user_for_comment_ids_hash(@user.id, diff --git a/app/views/comments/index.html.erb b/app/views/comments/index.html.erb index 7f09269..40b57bf 100644 --- a/app/views/comments/index.html.erb +++ b/app/views/comments/index.html.erb @@ -5,3 +5,16 @@ :show_story => true } %> <% end %> + + diff --git a/config/routes.rb b/config/routes.rb index 944c975..b3b5202 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -51,6 +51,7 @@ Lobsters::Application.routes.draw do post "delete" post "undelete" end + get "/comments/page/:page" => "comments#index" post "/comments/post_to/:story_id" => "comments#create" post "/comments/preview_to/:story_id" => "comments#preview_new"