From 158487dfc2c2d5710a8d4e76509cf9596022bd46 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 3 Mar 2014 12:56:37 -0500 Subject: [PATCH] FIX: Clean up next/prev rel links --- app/controllers/list_controller.rb | 7 ++++++- app/views/list/list.erb | 2 +- app/views/topics/show.html.erb | 16 ++++++++-------- lib/topic_view.rb | 16 ++++++++++++++++ 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index ce81915090e..8dd87b27b78 100644 --- a/app/controllers/list_controller.rb +++ b/app/controllers/list_controller.rb @@ -208,7 +208,12 @@ class ListController < ApplicationController end def prev_page_params(opts = nil) - page_params(opts).merge(page: params[:page].to_i > 1 ? (params[:page].to_i - 1) : 1) + pg = params[:page].to_i + if pg > 1 + page_params(opts).merge(page: pg - 1) + else + page_params(opts).merge(page: nil) + end end diff --git a/app/views/list/list.erb b/app/views/list/list.erb index 3e6d6c064aa..17d9e09615d 100644 --- a/app/views/list/list.erb +++ b/app/views/list/list.erb @@ -7,7 +7,7 @@ <% if @list.topics.length > 0 %>

- <% if params[:page].to_i > 1 %> + <% if params[:page].to_i > 0 %>   <% end %> diff --git a/app/views/topics/show.html.erb b/app/views/topics/show.html.erb index 6cd3b18cd21..182f4881852 100644 --- a/app/views/topics/show.html.erb +++ b/app/views/topics/show.html.erb @@ -16,14 +16,14 @@ <% end %> -<% if @topic_view.next_page %> -

- <% if params[:page].to_i > 1 %> -   - <% end %> - -

-<% end %> +

+ <% if @topic_view.prev_page %> + <%= link_to t(:prev_page), @topic_view.prev_page_path, rel: 'prev' %> + <% end %> + <% if @topic_view.next_page %> + <%= link_to t(:next_page), @topic_view.next_page_path, rel: 'next' %> + <% end %> +

<%= t 'powered_by_html' %>

diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 1cbec56ab5b..86bd1ee99f7 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -59,6 +59,14 @@ class TopicView @last_post ||= @posts.last end + def prev_page + if @page && @page > 1 + @page - 1 + else + nil + end + end + def next_page @next_page ||= begin if last_post && (@topic.highest_post_number > last_post.post_number) @@ -67,6 +75,14 @@ class TopicView end end + def prev_page_path + if prev_page > 1 + "#{@topic.relative_url}?page=#{prev_page}" + else + @topic.relative_url + end + end + def next_page_path "#{@topic.relative_url}?page=#{next_page}" end