2013-03-19 2 views
1

컨트롤러 (예 : ProductController)에서 다음과 같은 메소드가 나타납니다.레일 : 링크를 두 번 클릭하면 두 개의 팝업이 열림

def show 
    respond_with do |format| 
     format.html do 
     if request.xhr? 
      @product = ... 
      render :status => 200, :partial => 'products/show' 
     end 
     end 
    end 
    end 

사용자가 제품 링크를 클릭하면 제품 이미지 및 설명이있는 팝업이 열립니다.

문제점 : 지정된 사용자가 제품 링크를 두 번 클릭하면 두 개의 팝업이 열립니다. 디버깅하는 동안 ProductController#show 메서드는 한 번만 호출되지만 여전히 두 개의 팝업이 열리는 것으로 나타났습니다.

답변

1

아약스를 통해 서버에 요청을 보내고 있습니까? 두 번째 요청은 링크의 기본 동작입니다. 시도해보십시오

$("a.your_link").click(function(e){ 
    e.preventDefault(); // this will consume default functionality of your link 
    //now send request to server 
    $.ajax(url: your_url).done(function(output){ 
    alert(data); 
    }); 
}); 
관련 문제