2012-04-24 2 views
0

에서 렌더링 할 수 I는 A js.erb 파일에 다음과 같습니다 는 사용자가 js.erb 파일

//add an image from the gallery to the mail later 
    $('.uploaded_image').click(function(){ 

     var src=$(this).attr('src').replace("thumb", "medium"); 
     var location = $('#user_image_location').attr('value'); 
     $('#mailing_body').contents().find("[data-edit-img="+''+location+''+"]").attr('src', src); 
     $('#image_form').html('<%=render "user_images/form"%>'); 
     $('[data-dismiss]="cancel"').click(); 

    }) 

가 나는 페이지 콘텐츠를 대체 할 JS 파일에 ERB를 사용할 수 있다고 생각.

$('#image_form').html('<%=render "user_images/form"%>'); 

그것은 모든 작품 : 나는 다음 줄을 제거하면

undefined method `render' for #<#<Class:0x00000103dea400>:0x000001059f2198> 

: 나는 다음과 같은 오류가 발생합니다.

나는 3.2

왜이 작동하지 않습니다 내가 레일과 JS 파일에 ERB를 사용할 수 있다고 생각?

미리 감사드립니다.

답변

2

.js.erb 파일 내에 렌더링 (모든 도우미, 리소스 등 & 포함)을 사용할 수 있습니다 (확실한 것으로 확인되었습니다).

.js.erb를 들어 파일이 그들이 당신의 views 폴더 안에 배치해야합니다 .html.erb 파일과 같은 방식으로 처리 (예 : app/views/<controller> 또는 app/views/shared로), 그들은 당신의 app/assets/javascripts 폴더에 배치 할 수 없습니다.

+0

감사합니다. 마크가 삭제되었습니다. – chell