diff --git a/app/controllers/list_controller.rb b/app/controllers/list_controller.rb index ce8191509..8dd87b27b 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 3e6d6c064..17d9e0961 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 6cd3b18cd..182f48818 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 1cbec56ab..86bd1ee99 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