From e767ec729c7401c5c0551fa5aa880b1e4c829fae Mon Sep 17 00:00:00 2001 From: jomo Date: Mon, 22 Sep 2014 06:29:24 +0200 Subject: [PATCH] paginate blog comments; fix length/site on AR objects --- app/controllers/blogposts_controller.rb | 1 + app/controllers/users_controller.rb | 2 +- app/views/blogposts/show.html.erb | 5 +++-- app/views/forumthreads/show.html.erb | 2 +- app/views/layouts/_footer.html.erb | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 92beb68..79c9e5d 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -9,6 +9,7 @@ class BlogpostsController < ApplicationController def show @comment = Comment.new(blogpost: @post) + @comments = @post.comments.page(params[:page]) end def new diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 967c6c4..c1b738a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -22,7 +22,7 @@ class UsersController < ApplicationController @users = User.where.not(id: User.first.id) #Remove first user end @users = @users.order("role_id desc", "confirmed desc", :name) - @count = @users.length + @count = @users.size @users = @users.page(params[:page]).per(100) end diff --git a/app/views/blogposts/show.html.erb b/app/views/blogposts/show.html.erb index 0dae530..57532dc 100644 --- a/app/views/blogposts/show.html.erb +++ b/app/views/blogposts/show.html.erb @@ -17,9 +17,10 @@
-

<%= "#{pluralize(@post.comments.length, 'comment')}." %>

- <% @post.comments.each do |c| %> +

<%= "#{pluralize(@post.comments.size, 'comment')}." %>

+ <% @comments.each do |c| %> <%= render "comments/comment", c: c %> <% end %> + <%= paginate @comments %> <%= render "comments/new" %>
\ No newline at end of file diff --git a/app/views/forumthreads/show.html.erb b/app/views/forumthreads/show.html.erb index a3624c8..b07908b 100644 --- a/app/views/forumthreads/show.html.erb +++ b/app/views/forumthreads/show.html.erb @@ -20,7 +20,7 @@
-

<%= "#{pluralize(@thread.replies.length, 'reply')}." %>

+

<%= "#{pluralize(@thread.replies.size, 'reply')}." %>

<% @replies.each do |reply| %> <%= render partial: "threadreplies/reply", locals: {reply: reply} %> <% end %> diff --git a/app/views/layouts/_footer.html.erb b/app/views/layouts/_footer.html.erb index 02e30c9..be15b92 100644 --- a/app/views/layouts/_footer.html.erb +++ b/app/views/layouts/_footer.html.erb @@ -1,7 +1,7 @@ <% users = User.seen(2.minutes) %>