I have a set of pagination links in a table which gets refreshed in POST requests, with a turbo stream.
My problem is that if I click a pagination link immediately after I create a new Car record, the pagination links change to include the params of the new car, like so:-
localhost:3000/cars?page=2&car%5Bname%5D=volswagen
When normally, they are just:-
localhost:3000/cars?page=2
Then what happens when I go to create another Car, my post request includes the params of the previous car (above) and disregards what's in my form.
Anyone know why this is happening?
index.html.slm
# table with id="car-table"
# contents...
= paginate @cars, params: { controller: 'admin/cars', action: 'index' }
create.turbo_stream.erb
<%= turbo_stream.replace('car-table', partial: 'table', locals: { cars: @cars }) %>
cars_controller.rb
def index
@cars = Car.all.page(params[:page])
respond_to do |format|
format.turbo_stream { render :index }
end
end
def create
@car = Car.create(car_params)
@cars = Car.all.page(params[:page])
respond_to do |format|
format.turbo_stream { render :create }
end
end