2012-04-24 67 views
0

我有一个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(); 

    }) 

我以为我可以使用ERB在js文件在页面上更换内容。 我得到以下错误:

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

如果我删除以下行:

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

它所有的作品。

我认为我可以在使用Rails js文件使用ERB 3.2

为什么这个不行?

在此先感谢。

回答

2

你当然可以在你的.js.erb文件中使用渲染(包括任何&所有帮助程序,资源等)(我刚刚证实是确定的)。

对于.js.erb要处理的文件的方式为您.html.erb文件必须放在你的views文件夹内相同(如app/views/<controller>app/views/shared),它们不能被放置在你的app/assets/javascripts文件夹中。

+0

谢谢马克,清除了 – chell 2012-04-25 05:17:53