Ruby on rails 如何定制';类型';Rails中javascript_标记助手的属性?

Ruby on rails 如何定制';类型';Rails中javascript_标记助手的属性?,ruby-on-rails,ruby,ruby-on-rails-3,handlebars.js,Ruby On Rails,Ruby,Ruby On Rails 3,Handlebars.js,如何向Rails中的javascript\u标记添加自定义type属性 <%= javascript_tag id: 'entry-template', type: 'text/x-handlebars-template' do %> <div class="entry"> <h1>{{title}}</h1> <div class="body"> {{body}} </div>

如何向Rails中的
javascript\u标记添加自定义
type
属性

<%= javascript_tag id: 'entry-template', type: 'text/x-handlebars-template' do %>
  <div class="entry">
    <h1>{{title}}</h1>
    <div class="body">
      {{body}}
    </div>
  </div>
<% end %>

{{title}}
{{body}}
上述申报表:

<script id="entry-template" type="text/javascript">
  <div class="entry">
    <h1>{{title}}</h1>
    <div class="body">
      {{body}}
    </div>
  </div>
</script>

{{title}}
{{body}}
所需输出为:

<script id="entry-template" type="text/x-handlebars-template">
  <div class="entry">
    <h1>{{title}}</h1>
    <div class="body">
      {{body}}
    </div>
  </div>
</script>

{{title}}
{{body}}

javascript\u tag
是用于,嗯,javascript的,它在名称中这么说。如果要将
用作非JavaScript的容器,只需手工编写即可:

<script id="entry-template" type="text/x-handlebars-template">
    alert('All is not good');
</script>
我不认为使用
content\u标签有什么意义,只是看起来事情太复杂了。

试试看

<%= javascript_tag :html_options => {id => 'entry-template', :type => 'text/x-handlebars-template'} do %>
    ------------------------
    ----------------------- 
<%end%>
{id=>'entry template',:type=>'text/x-handlebar-template'}do%>
------------------------
----------------------- 

但愿它能奏效。我还没试过。

问得好。我查看了的源代码,它似乎在使用,但我找不到自动设置
:type
的原因。也许文档已经过时了。PS:现在就使用html版本吧。总之,它比较短:谢谢你的输入。“javascript_标记”助手的挑剔本质确实很奇怪!由于我的问题含糊不清,你的玩笑有些道理。我想我对助手的需求归结为与其他开发人员的一致性。内容标签就可以了。谢谢。如果需要,您可以添加自己的
车把标签
助手。这将使您与
javascript_标记
具有某种对称性,并有助于确保具有一致的
类型
属性。还有一个宝石,用于预编译您可能感兴趣的所有把手模板:我一定会研究您的两个建议!再次感谢。
<%= javascript_tag :html_options => {id => 'entry-template', :type => 'text/x-handlebars-template'} do %>
    ------------------------
    ----------------------- 
<%end%>