]> git.openstreetmap.org Git - rails.git/commitdiff
Make pagination partial view
authorAnton Khorev <tony29@yandex.ru>
Mon, 4 Sep 2023 12:07:54 +0000 (15:07 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 9 Sep 2023 11:23:12 +0000 (14:23 +0300)
app/views/diary_entries/_pagination.html.erb [new file with mode: 0644]
app/views/diary_entries/comments.html.erb
app/views/diary_entries/index.html.erb

diff --git a/app/views/diary_entries/_pagination.html.erb b/app/views/diary_entries/_pagination.html.erb
new file mode 100644 (file)
index 0000000..63a0fc3
--- /dev/null
@@ -0,0 +1,23 @@
+<nav>
+  <ul class="pagination">
+    <% if instance_variable_get("@newer_#{name}") -%>
+      <li class="page-item">
+        <%= link_to t("newer_#{name}", :scope => scope), @params.merge(:after => instance_variable_get("@#{name}").first.id), :class => "page-link" %>
+      </li>
+    <% else -%>
+      <li class="page-item disabled">
+        <span class="page-link"><%= t("newer_#{name}", :scope => scope) %></span>
+      </li>
+    <% end -%>
+    
+    <% if instance_variable_get("@older_#{name}") -%>
+      <li class="page-item">
+        <%= link_to t("older_#{name}", :scope => scope), @params.merge(:before => instance_variable_get("@#{name}").last.id), :class => "page-link" %>
+      </li>
+    <% else -%>
+      <li class="page-item disabled">
+        <span class="page-link"><%= t("older_#{name}", :scope => scope) %></span>
+      </li>
+    <% end -%>
+  </ul>
+</nav>
index 2ffce6ff6d2817e995cbde2d3dc76d1c0e8bb06a..56c0e76c5fd97ece4b7c22f25cd9bc945562c6b4 100644 (file)
     <% end -%>
   </table>
 
-  <nav>
-    <ul class="pagination">
-      <% if @older_comments -%>
-        <li class="page-item">
-          <%= link_to t(".older_comments"), @params.merge(:before => @comments.last.id), :class => "page-link" %>
-        </li>
-      <% else -%>
-        <li class="page-item disabled">
-          <span class="page-link"><%= t(".older_comments") %></span>
-        </li>
-      <% end -%>
-
-      <% if @newer_comments -%>
-        <li class="page-item">
-          <%= link_to t(".newer_comments"), @params.merge(:after => @comments.first.id), :class => "page-link" %>
-        </li>
-      <% else -%>
-        <li class="page-item disabled">
-          <span class="page-link"><%= t(".newer_comments") %></span>
-        </li>
-      <% end -%>
-    </ul>
-  </nav>
+  <%= render "pagination", :name => "comments", :scope => "diary_entries.comments" %>
 <% end -%>
index e95b31bb2b88e901591a907dca9fe1a63c7fac36..e4cc8fc8e6ffd7768e51c260ef33a19ba3883a6f 100644 (file)
 
   <%= render @entries %>
 
-  <nav>
-    <ul class="pagination">
-      <% if @newer_entries -%>
-        <li class="page-item">
-          <%= link_to t(".newer_entries"), @params.merge(:after => @entries.first.id), :class => "page-link" %>
-        </li>
-      <% else -%>
-        <li class="page-item disabled">
-          <span class="page-link"><%= t(".newer_entries") %></span>
-        </li>
-      <% end -%>
-
-      <% if @older_entries -%>
-        <li class="page-item">
-          <%= link_to t(".older_entries"), @params.merge(:before => @entries.last.id), :class => "page-link" %>
-        </li>
-      <% else -%>
-        <li class="page-item disabled">
-          <span class="page-link"><%= t(".older_entries") %></span>
-        </li>
-      <% end -%>
-    </ul>
-  </nav>
+  <%= render "pagination", :name => "entries", :scope => "diary_entries.index" %>
 <% end %>
 
 <% unless params[:friends] or params[:nearby] -%>