Ruby on rails - 渲染.js.erb文件中的部分文件

时间:2022-11-07 08:47:18

In the HTML header this small javascript works:

在HTML标头中,这个小的javascript工作:

application.html.erb

application.html.erb

<script type="text/javascript">
               alert("<%= escape_javascript(render('resources/positions')) %>");
</script>

But When I tried to put the same code in a js.erb file, it doesn't work.

但是当我试图将相同的代码放在js.erb文件中时,它不起作用。

I tried to inlcude the file, but not working both ways:

我试图包含文件,但不是两种方式:

<script src="/assets/resources.js.erb" type="text/javascript"></script>
<%= javascript_include_tag 'resources' %>

app/assets/javascripts/resources.js.erb

应用程序/资产/ JavaScript的/ resources.js.erb

alert("<%= escape_javascript(render('resources/positions')) %>");

any ideas ?

有任何想法吗 ?

Thanks in advance for any help.

在此先感谢您的帮助。

1 个解决方案

#1


1  

Sounds like a problem with the asset pipeline.

听起来像资产管道的问题。

Try adding

尝试添加

config.serve_static_assets = true

In development.rb

在development.rb

#1


1  

Sounds like a problem with the asset pipeline.

听起来像资产管道的问题。

Try adding

尝试添加

config.serve_static_assets = true

In development.rb

在development.rb