]> git.openstreetmap.org Git - rails.git/commitdiff
Don't interpolate in pagination partial
authorAnton Khorev <tony29@yandex.ru>
Mon, 4 Sep 2023 12:41:09 +0000 (15:41 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sat, 9 Sep 2023 11:33:58 +0000 (14:33 +0300)
app/controllers/diary_entries_controller.rb
app/views/diary_entries/_pagination.html.erb
app/views/diary_entries/comments.html.erb
app/views/diary_entries/index.html.erb

index e7eb53d59bba0e53db76005748db00b5bbbab42c..5b522988d2de1362a06bc10e51d8819fa717be44 100644 (file)
@@ -55,7 +55,7 @@ class DiaryEntriesController < ApplicationController
 
     @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
@@ -240,7 +240,7 @@ class DiaryEntriesController < ApplicationController
 
     @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
@@ -291,9 +291,9 @@ class DiaryEntriesController < ApplicationController
     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
index 63a0fc3e278ba697144158f4ddf3acfea5d42d6d..4a948a4f53378fee502a599bd475d609b344fb18 100644 (file)
@@ -1,22 +1,22 @@
 <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>
index 56c0e76c5fd97ece4b7c22f25cd9bc945562c6b4..e1d92b6bb804bb13e55a19b5326453edb446f672 100644 (file)
@@ -24,5 +24,8 @@
     <% 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 -%>
index e4cc8fc8e6ffd7768e51c260ef33a19ba3883a6f..f6e2c37c5f5ee9f9d408809a0f75022b16555bee 100644 (file)
 
   <%= 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] -%>