jquery-rails breaks kaminari?

删除回忆录丶 提交于 2019-12-21 23:15:54

问题


I updated my Rails 3.0.7 application to use kaminari 0.12.4 (up from 0.10.4) for pagination and jquery-rails 1.0.9 and it seemed to break pagination. I've regenerated the kaminari views since they are different but for some reason ajax isn't working.

<%= javascript_include_tag :defaults %>

is included. Which produces this in the browser:

<script src="/javascripts/jquery.js?1306353646" type="text/javascript"></script> 
<script src="/javascripts/jquery-ui.js?1306368501" type="text/javascript"></script> 
<script src="/javascripts/jquery_ujs.js?1306381513" type="text/javascript"></script> 
<script src="/javascripts/application.js?1290034766" type="text/javascript"></script>

In my view I have: <%= paginate @users, :remote => true %>

Which yields the following error:

ActionView::MissingTemplate (Missing template users/show with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:js, "application/ecmascript", "application/x-ecmascript", "/"], :locale=>[:en, :en]} in view paths "/home/epipheus/CodeWarehouse/praypeer/app/views", "/home/epipheus/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/kaminari-0.12.4/app/views"):

the following non-ajax version works just fine of course:

<%= paginate @users, :remote => false %>

So it seems like I have something wrong with jquery ujs? Please help me.


回答1:


Turns out that for jquery kaminari needs you to insert the following to say show.js.erb for example:

$('#microposts').html('<%= escape_javascript render(@microposts) %>');
$('.app-table-pager').html('<%= escape_javascript(paginate(@microposts, :remote => true).to_s) %>');

If you don't switch to jquery-rails/ujs -- out of the box, it doesn't seem you need this.




回答2:


I recently had problems with jquery-rails after update. I updated the gem via bundler, but it was not quite compatible with an existing jquery-rails files. After I ran "rails generate jquery:install" command, I did not see any more errors.



来源:https://stackoverflow.com/questions/6134028/jquery-rails-breaks-kaminari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!