FIX: Clean up next/prev rel links

This commit is contained in:
Robin Ward 2014-03-03 12:56:37 -05:00
parent 6143753fef
commit 158487dfc2
4 changed files with 31 additions and 10 deletions

View file

@ -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

View file

@ -7,7 +7,7 @@
<% if @list.topics.length > 0 %>
<p>
<% if params[:page].to_i > 1 %>
<% if params[:page].to_i > 0 %>
<a href="<%= @list.prev_topics_url.sub('.json?','?') %>" rel="prev"><%= t 'prev_page'%></a> &nbsp;
<% end %>
<b><a href="<%= @list.more_topics_url.sub('.json?','?') %>" rel="next"><%= t 'next_page'%></a></b>

View file

@ -16,14 +16,14 @@
<% end %>
<% if @topic_view.next_page %>
<p>
<% if params[:page].to_i > 1 %>
<a href="" rel="prev"><%= t 'prev_page'%></a> &nbsp;
<% end %>
<b><a href="<%= @topic_view.next_page_path %>" rel="next"><%= t 'next_page'%></a></b>
</p>
<% end %>
<p>
<% if @topic_view.prev_page %>
<%= link_to t(:prev_page), @topic_view.prev_page_path, rel: 'prev' %>
<% end %>
<% if @topic_view.next_page %>
<b><%= link_to t(:next_page), @topic_view.next_page_path, rel: 'next' %></b>
<% end %>
</p>
<p><%= t 'powered_by_html' %></p>

View file

@ -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