Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery_ujs conflicts with Kaminari AJAX in Rails 4?

Short version; jquery_ujs appears to conflict with Kaminari's AJAX support and I don't know why.

In my Rails 4 app, I have the following lines in my application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require_tree .

If I remove jquery_ujs, then the following code stops working; it starts sending GET requests instead of DELETE requests and the user, per sending a GET request, simply receives the show page for the resource.

<%= link_to 'Delete Horse', horse, method: :delete, data: { confirm: 'Are you sure?' } %>

But if I leave jquery_ujs in, Kaminari w/ AJAX stops working....

<%= paginate @horses, :remote => true %>

goes nowhere when clicked (though the HREF tag in the rendered HTML is correct).

If I remove :remote => true from the paginate @horses link, then the link starts working. But, A) I'd like the AJAX to work for the sake of user experience, and B) I would like to understand why this is all happening.

like image 315
NBarnes Avatar asked Nov 11 '22 17:11

NBarnes


1 Answers

You will need to have your js.erb file to handle the request from Kaminari. In your js.erb, you should place the Javascript code to replace the current content with your new content from server.

So in your case, it sends the request as JS and that is the correct behavior. You can look at the reference here. http://jyothu-mannarkkad.blogspot.com/2013/06/rails-kaminari-ajax-pagination.html

like image 112
The Lazy Log Avatar answered Nov 15 '22 11:11

The Lazy Log