@params = params.permit(:display_name, :friends, :nearby, :language)
- @entries, @newer_entries, @older_entries = get_page_items(entries, [:user, :language])
+ @entries, @newer_entries_id, @older_entries_id = get_page_items(entries, [:user, :language])
end
def show
@params = params.permit(:display_name)
- @comments, @newer_comments, @older_comments = get_page_items(comments, [:user])
+ @comments, @newer_comments_id, @older_comments_id = get_page_items(comments, [:user])
end
private
page_items = page_items.includes(includes)
page_items = page_items.sort.reverse
- newer_items = page_items.count.positive? && items.exists?(["#{id_column} > ?", page_items.first.id])
- older_items = page_items.count.positive? && items.exists?(["#{id_column} < ?", page_items.last.id])
+ newer_items_id = page_items.first.id if page_items.count.positive? && items.exists?(["#{id_column} > ?", page_items.first.id])
+ older_items_id = page_items.last.id if page_items.count.positive? && items.exists?(["#{id_column} < ?", page_items.last.id])
- [page_items, newer_items, older_items]
+ [page_items, newer_items_id, older_items_id]
end
end
<nav>
<ul class="pagination">
- <% if instance_variable_get("@newer_#{name}") -%>
+ <% if newer_id -%>
<li class="page-item">
- <%= link_to t("newer_#{name}", :scope => scope), @params.merge(:after => instance_variable_get("@#{name}").first.id), :class => "page-link" %>
+ <%= link_to t(newer_key), @params.merge(:after => newer_id), :class => "page-link" %>
</li>
<% else -%>
<li class="page-item disabled">
- <span class="page-link"><%= t("newer_#{name}", :scope => scope) %></span>
+ <span class="page-link"><%= t(newer_key) %></span>
</li>
<% end -%>
-
- <% if instance_variable_get("@older_#{name}") -%>
+
+ <% if older_id -%>
<li class="page-item">
- <%= link_to t("older_#{name}", :scope => scope), @params.merge(:before => instance_variable_get("@#{name}").last.id), :class => "page-link" %>
+ <%= link_to t(older_key), @params.merge(:before => older_id), :class => "page-link" %>
</li>
<% else -%>
<li class="page-item disabled">
- <span class="page-link"><%= t("older_#{name}", :scope => scope) %></span>
+ <span class="page-link"><%= t(older_key) %></span>
</li>
<% end -%>
</ul>
<% end -%>
</table>
- <%= render "pagination", :name => "comments", :scope => "diary_entries.comments" %>
+ <%= render "pagination", :newer_key => "diary_entries.comments.newer_comments",
+ :older_key => "diary_entries.comments.older_comments",
+ :newer_id => @newer_comments_id,
+ :older_id => @older_comments_id %>
<% end -%>
<%= render @entries %>
- <%= render "pagination", :name => "entries", :scope => "diary_entries.index" %>
+ <%= render "pagination", :newer_key => "diary_entries.index.newer_entries",
+ :older_key => "diary_entries.index.older_entries",
+ :newer_id => @newer_entries_id,
+ :older_id => @older_entries_id %>
<% end %>
<% unless params[:friends] or params[:nearby] -%>