繁体   English   中英

无法在js.erb文件中进行用户渲染

[英]can't user render in js.erb file

我在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来替换页面上的内容。 我收到以下错误:

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

如果我删除以下行:

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

一切正常。

我以为我可以在使用Rails 3.2的js文件中使用erb

为什么这不起作用?

提前致谢。

你当然可以在你的.js.erb文件中使用render(包括任何&所有助手,资源等)(我只是确认是确定的)。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM