0

I'm having a weird problem with Kaminari, AJAX pagination and the latest rails.

I see everything is working perfectly underneath, it's doing the right calls, generating the right HTML and JS, but for reasons I don't understand it doesn't update the page after a pagination AJAX call.

The js it produces can be cut&pasted in Chrome JS console and it works perfectly(???)

My controller

def show
  @facility = Facility.friendly.find(params[:id]).decorate
  @pets = @facility.pets.page(params[:page]).per(1)
  respond_to do |format|
    format.html
    format.js do
      render 'pets/pets', layout: false
    end
  end
end

pets/pets.js.haml

:javascript
  $('#pets').html("#{escape_javascript(render(partial: 'pets/pets', locals: {pets: @pets}))}");

pets/_pets.html.haml

#pets
  .row.products
    = render pets

= paginate pets, remote: true

What can be the reason for not updating the page? The js appears to be correct but it doesn't sort any effect if it comes from Rails, only if I paste it on the console (the same exact JS, pasted from the debug console)

If someone can help me, I'm literally going nuts, and I want to solve this at least as much as I know that the problem will 99% be my fault and after I will like hang myself :)

TIA - ngw

ngw
  • 1,222
  • 1
  • 14
  • 34

2 Answers2

0

It is seems you missed the rails <%= %> tag

:javascript $('#pets').html(<%= "#{escape_javascript(render(partial: 'pets/pets', locals: {pets: @pets}))}" %>);

ruwhan
  • 117
  • 2
  • 13
0

pets should belongs to show.html.erb

cjhveal
  • 5,668
  • 2
  • 28
  • 38
Johnny Dương
  • 753
  • 3
  • 8