Rails-pagy-gem与turbo帧操作导致错误的url生成分页



我在应用程序中使用pagy-gem进行分页,并使用turbo帧进行交互式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 %>

您应该使用:request_path变量(在pagy v6.0+中可用(,如Customize the request_path中所示。

我想以下内容应该适用于您的情况:

@pagy, @toponyms = pagy(Toponym.order(created_at: :desc), request_path: '/toponyms')

相关内容

  • 没有找到相关文章

最新更新