首页 文章

如何在rails上呈现原始erb内容

提问于
浏览
3

我一直在尝试渲染一个underscore.js模板,就像某些haml内容上的ERB一样 .

但随着模板的增长,我不想做更多这样的事情

%script{:type => "text/template", :id => "my_template"}
  :plain
    <div><%= my_js_value %></div>
    .....(other content)...

而不是我想使用部分内部渲染它我希望做的事情如下:

%script{:type => "text/template", :id => "my_template"}
    =render :file => "mytemplate.txt"

但是这个渲染尝试将ERB绑定在它上面,而且我的my_js_value有错误

我通过这种方式进行渲染的唯一方法是:

%script{:type => "text/template", :id => "my_template"}
    =render :text => File.read("#{Rails.root}/app/views/mycontroller/mytemplate.txt")

最后一个对我有用,但我一直在寻找比这更好的东西 .

你建议我做什么而不是阅读文件?渲染中没有“原始”选项吗?

BTW这是在轨道2.3.14应用程序

1 回答

相关问题