是否有任何可能的方式来解决这个问题雷分页产生的网址是什么?(Is there any possibl

2019-07-17 18:24发布

我正在执行一项即时通讯系统,我的应用程序,其中只有注释的名单将与阿贾克斯提交重新加载。

雷分页中有使用,但在其网址这样会很奇怪串新的评论被提交后。

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

它变得更加奇怪的说法参数的URL时,评论是在提交其他控制器。 只有当它被用macthed 垃圾邮件错误生成的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

<%= javascript_tag do %>
    jQuery(document).ready(function () {
        refreshPartial();
        setInterval(refreshPartial, 5000)
    });


    function refreshPartial() {
      $.ajax({
        url: "<%= show_user_path(@user) %>/refresh_part",
        type: "GET",
        dataType: "script",
      });
    }
<% end %>
......
<span id="chat">
<%= render 'users/comment' %>
</span>
<%= render 'users/comment_input' %>

意见/用户/ _comment.html.erb

<table>
  <tr>
    <th>ID</th>
    <th>PIC</th>
    <th>Body</th>
    <th>Subject</th>
    <th>Posted by</th>
    <th>Delete</th>
  </tr>

<% @comments.each do |comment| %>
  <tr id="<%= dom_id(comment) %>">
    <td><%= comment.id %></td>
    <td>
            <% if comment.comment_icon? %>
                <ul class="thumbnails">
                <%= image_tag(comment.comment_icon.url(:thumb),:height => 100, :width => 100, :style => 'border:3px double #545565;' ) %>
                </ul>
            <% end %>

    </td>
    <td><%= comment.body %></td>
    <td><%= comment.subject %></td>
    <td><%= comment.user.user_profile.nickname if comment.user.user_profile %></td>
    <td>
    <%= button_to 'destroy', polymorphic_path([@user, comment]), :data => {:confirm => 'Are you sure?'}, :method => :delete, :disable_with => 'deleting...', :remote => true, :class => 'btn btn-danger' if current_user && current_user.id == comment.user_id %>
    </td>
    </tr>
<% end %>
</table>

<%= paginate @comments, :window => 4, :outer_window => 5, :left => 2, :right => 2 %>

视图/用户/ _comment_input.html.erb <=这是输入表格!!!!!

<%=form_for(([@user, @comment]), :remote => true) do |f| %>
    <div class="field">
      <%= f.label :body %><br />
      <%= f.text_field :body %>
    </div>
    <div class="field">
    <%= f.file_field :comment_icon %>
    </div>
  <div class="actions">
    <%= f.submit %>
  </div>

<% end %>

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) <= 10.second  
    flash[:notice] = "You cannot spam!" 
    render :template => 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("<%= j(render(:partial => 'users/comment')) %>")

Answer 1:

这是一个已知的问题与雷。 参见: 问题#132 , 问题#182 。

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

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

你必须调整代码,以适应您的情况,一定要测试所有其他功能工作正常,当你手动设置所有PARAMS。

既然你具体遇到的URL时间戳的问题,您应该对问题132发表评论,并发布你的经验细节那里。 你越是参与到GitHub上发出更可能是你,该项目的用户和维护者将能够找到更好的解决方案。



文章来源: Is there any possible way to fix the url that Kaminari pagination generates?