I'm trying to on top of paginating using ajax, use the pushState to update the url. The problem I'm having is that it only executes the first time.
My complete setup is the following
Rails 3.2, Jquery, Kaminari(pagination gem)
so here is the code I use for updating url
jQuery ->
$(".pagination a[data-remote=true]").on 'click', (e) ->
e.preventDefault()
history.pushState {}, '', $(this).attr("href")
And on show.js.erb, to update the content I use
$("#reviews").html('<%= escape_javascript render("review") %>')
$("#paginator").html('<%= escape_javascript(paginate(@reviews, :remote => true).to_s) %>');
The show works every time, but the first script does it only the first time.
If I put a break point on the generated script, I can see when the script is first called, it works but afterwards it is never called, as if there was some sort of unbinding I guess.
Try:
Probably all
.pagination a[data-remote=true]
links are in#paginator
container which content is updated inshow.js.erb
. You need to repeat bind withon
method after html replace OR just delagate event handler from parent container [readon
documentation for details]With jquery-ujs, this is what I do:
In show.html.erb:
In show.js.erb:
In application.js: