【发布时间】:2023-02-01 12:32:49
【问题描述】:
我在我的应用程序中使用 pagy gem 进行分页,使用 turbo frames 进行交互式 CRUD 操作。
我要更新分页和列表项框架当我删除一些记录时使用 turbo_stream.erb 操作。一切正常,期望分页链接。他们一定像...
/toponyms?page=1
/toponyms?page=2
但是当我销毁记录分页链接时,如下所示。
#because of deleted record id = 278
/toponyms278?page=1
/toponyms278?page=2
控制器
def destroy
authorize @toponym
@toponym.destroy
flash[:info] = "Toponym was successfully destroyed."
# This code must be here for update pagination after delete
@pagy, @toponyms = pagy(Toponym.order(created_at: :desc))
puts @pagy
respond_to do |format|
format.turbo_stream
format.html { redirect_to toponyms_url, notice: "Toponym was successfully destroyed." }
format.json { head :no_content }
end
end
#destroy.turbo_stream.erb
<%= turbo_stream.update "total" do %>
<%== pagy_nav(@pagy) %>
<%== pagy_info(@pagy) %>
<% end %>
【问题讨论】:
-
您找到解决方案了吗?我对涡轮流有类似的问题。
-
这个 Youtube 视频帮助了我:如何使用 Hotwire (youtu.be/HURqvNJF4T0) 向您的数据表添加过滤和分页
-
我无法修复更新分页问题。分页有效,但在一些 crud 操作后更新无效。分页链接保持不变。
标签: ruby-on-rails turbo-frames pagy