有没有办法修复Kaminari分页产生的url?

我正在为我的应用程序实现一个聊天系统,其中只有注释列表将使用ajax submit重新加载。

在那里使用Kaminari分页 ,但在提交新评论后,它会在其URL中得到奇怪的字符串。

example-website.com/users/mike/refresh_part?_=1356906069855&page=2

当在其他控制器中提交注释时,它在其URL中获得更奇怪的参数参数。 仅当它与垃圾邮件错误相关时生成的URL:

example-website.com/shop/walmart/topic/20/comments?authenticity_token=9nUyEQ%2Fa0F114vUe16RXf7jhsPw%2B736E%2BKyZFjiWbkQ%3D&comment[body]=test&commit=Create+Comment&page=2&utf8=✓

我怎样才能解决这个问题?

我的代码是

意见/用户/ show.html.erb

 jQuery(document).ready(function () { refreshPartial(); setInterval(refreshPartial, 5000) }); function refreshPartial() { $.ajax({ url: "/refresh_part", type: "GET", dataType: "script", }); }  ......     

意见/用户/ _comment.html.erb

   <tr id=""> 
ID PIC Body Subject Posted by Delete
    100, :width => 100, :style => 'border:3px double #545565;' ) %>
{:confirm => 'Are you sure?'}, :method => :delete, :disable_with => 'deleting...', :remote => true, :class => 'btn btn-danger' if current_user && current_user.id == comment.user_id %>
4, :outer_window => 5, :left => 2, :right => 2 %>

views / users / _comment_input.html.erb <=这是输入表单!!!!!

  true) do |f| %> 

comments_controller.rb

 def create commentable = @community_topic||@community||@user @comments = commentable.comment_threads.order("updated_at DESC").page(params[:page]).per(5) @comment = Comment.build_from(commentable, current_user.try(:id), params[:comment][:body]) @comment.comment_icon = params[:comment][:comment_icon] if @user @following_users = @user.all_following(order: 'updated_at DESC') @followed_users = @user.followers @communities_user = @user.get_up_voted(Community).order("updated_at ASC").page(params[:page]).per(5) elsif @community end last_comment = Comment.where(:user_id => current_user.id).order("updated_at").last if last_comment && (Time.now - last_comment.updated_at)  template_for(commentable) elsif @comment.save #if @community_topic.empty? @comments = commentable.comment_threads.order("updated_at DESC").page(params[:page]).per(5) @comment = commentable.comment_threads.build respond_to do |format| format.html { redirect_to [@community, commentable].uniq, :notice => "comment added!" } format.js do if @community.present? render 'communities/refresh_part' elsif @community_topic.present? render 'community_topics/refresh_part' elsif @user.present? render 'users/refresh_part' end end end else render :template => template_for(commentable) end end 

意见/用户/ refresh_part.js.erb

 $('#chat').html(" 'users/comment')) %>") 

这是Kaminari的一个已知问题。 请参阅: 问题#132 , 问题#182 。

目前已知的解决方法是在分页助手上手动设置params,例如:

 paginate @comments, :params => { :controller => 'comments', :action => 'index', _: nil, _method: nil, authenticity_token: nil, utf8: nil} 

您必须调整该代码以适合您的情况,并确保在手动设置所有参数时测试所有其他function是否按预期工作。

由于您在url上遇到时间戳问题,因此您应该对问题132发表评论,并在那里发布您的体验详情。 您参与github问题的次数越多,您,项目用户和维护人员就越有可能找到更好的解决方案。