2012-05-08 4 views
1

저는 자원 봉사자와 이벤트를 관리하는 Rails 3.2.3 응용 프로그램이 있습니다. 제 견해 중 하나에서 저는 자원 봉사자 행사를 파괴하기위한 링크를 만들고 있습니다. 나는 data-remote = true를 사용하고있다. 컨트롤러가 올바르게 실행되고 Rails가 내 destroy.js.erb를 렌더링 중이지만 파일 내의 스크립트가 호출되지 않는다고 말합니다. 내 스크립트에서 DIV 요소를 삭제하고 범위의 내용을 업데이트하려고합니다.브라우저가 destroy.js.erb에 응답하지 않습니다.

내보기 코드 :

<%= link_to '', event, method: :delete, confirm: "Are you sure you want to delete this volunteer posting?", title: event.name, class: "icon-remove", remote: true%> </li> 

내 컨트롤러 코드 : ...

respond_to :html, :js 

def destroy 
    @volunteer_event = VolunteerEvent.find(params[:id]) 
    @volunteer_event.destroy 

    respond_with(@volunteer_event) 

end 

내 destroy.js.erb

여기에 세부 사항 중 일부입니다
$("#hours_worked_total").html("<%= @volunteer_event.worker.account.total_hours_worked %>") 

$("#volunteer_posting-<%[email protected]_event.id %>") 
    .fadeOut -> 
     $(this).remove() 

이 뷰에 내장 결과 HTML입니다 :

Response: 
$("#hours_worked_total").html("0") 


$("#volunteer_posting-48") 
    .fadeOut -> 
    $(this).remove() 

Content-Type:text/javascript; charset=utf-8 
:

Started DELETE "/volunteer_events/48" for 127.0.0.1 at 2012-05-08 11:17:50 -0400 
... 
Rendered volunteer_events/destroy.js.erb (2.7ms) 

이 브라우저 요청 및 응답은 다음과 같습니다

<ol class="events"> 
<div id="volunteer_posting-48"> 
<li><strong>9808</strong> worked on August 5, 2012 by <i>Louie Ferry</i> for a total of 5 hours. 
<a href="/volunteer_events/48" class="icon-remove" data-confirm="Are you sure you want to delete this volunteer posting?" data-method="delete" data-remote="true" rel="nofollow" title="9808"></a> </li> 
</div> 
</ol> 

이 서버 로그입니다

답변

4

당신은 erb 파일에서 coffeescript를 사용합니다. 어느 destroy.js.coffee로 이름을 바꾸거나 다음과 같이 변경 :

$("#hours_worked_total").html("<%= @volunteer_event.worker.account.total_hours_worked %>"); 

$("#volunteer_posting-<%[email protected]_event.id %>").fadeOut(function(){ 
    $(this).remove(); 
}); 
+0

이 나는 ​​커피 깨달았다하지만 어떤 이유로 나는 그것이 JS 파일 내에서 교환 생각했다. 내 실수와 감사 딜란. 이것은 내 첫 번째 레일 애플 리케이션입니다. – jplumey

관련 문제