2013-01-02 3 views
5

내 앱에 채팅 시스템을 구현하고 있었는데, 댓글 목록 만 ajax submit과 함께 다시로드됩니다.Kaminari 페이지 매김이 생성하는 URL을 수정할 수있는 방법이 있습니까?

카미나리 페이지 매기기이 거기에 사용되었지만 새 덧글이 제출 된 후 URL에 이상한 문자열이 표시됩니다.

example-website.com/users/mike/refresh_part?_=1356906069855 & 페이지 = 2

와 의견이 다른에 제출되었을 때 그것의 URL에서 더 이상 인수 매개 변수를 가져옵니다 제어 장치. 이 스팸 오류 생성 된 URL로 macthed 된 경우에만 :

는 & 코멘트를 example-website.com/shop/walmart/topic/20/comments?authenticity_token=9nUyEQ%2Fa0F114vUe16RXf7jhsPw%2B736E%2BKyZFjiWbkQ%3D [몸] = 테스트 & 커밋 = 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 %> 

views/users/_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')) %>") 

답변

13

이 미나리 알려진 문제이다. 참조 : Issue #132, Issue #182.

현재 알려진 해결 방법은 수동으로 예를 들어, 페이지 매김 도우미에 PARAMS을 설정하는 것입니다 :

paginate @comments, :params => { :controller => 'comments', :action => 'index', _: nil, _method: nil, authenticity_token: nil, utf8: nil} 
당신은 당신의 상황에 맞게, 그리고 다른 모든 기능하는지 테스트해야하는 그 코드를 조정해야합니다

모든 매개 변수를 수동으로 설정할 때 예상대로 작동합니다.

URL에 타임 스탬프 문제가 특히 발생 했으므로 문제 132에 댓글을 달고 여기에 경험 사항을 게시해야합니다. github 문제에 참여할수록 프로젝트 사용자와 관리자가 더 나은 솔루션을 찾을 수 있습니다.

+0

고마워 :) 나는 당신의 제안을 시도했다. 그러나 ** disable = remote ** = true ** : 왜 그런지 말해 줄 수 있습니까? ** % = 페이지 매김 at_comments, : window => 4, : outer_window => 5, : left => 2, : 오른쪽 => 2, : params => {: 컨트롤러 => '커뮤니티', : action => 'show', _ : nil, _method : nil, authenticity_token : nil, utf8 : nil} % ** ** – MKK

+0

글쎄, ': remote => true'를'paginate'에 대한 인수 목록에 넣으면됩니다. – Andrew

+0

대단히 감사합니다 :) – MKK

관련 문제