I am using pagy gem for pagination and turbo frames for interactive CRUD operations in my application.
I want to update pagination and list item frames with turbo_stream.erb actions when i delete some record. Everything works correct expect pagination links. They must be like...
/toponyms?page=1
/toponyms?page=2
But when i destroy a record pagination link occurs like below.
#because of deleted record id = 278
/toponyms278?page=1
/toponyms278?page=2
controller
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 %>
You should use the :request_path
variable (available in pagy v6.0+) as indicated in Customize the request_path .
I guess something like the following should work in your case:
@pagy, @toponyms = pagy(Toponym.order(created_at: :desc), request_path: '/toponyms')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.