我正在使用Backbone构建一个Rails应用程序作为前端框架。我正在使用Handlebars进行模板化。
在Rails方面,我有一个出版物模型,每个出版物都有很多文章。现在我想将我的出版物名称列表打印到屏幕上。
当我将我的出版物集合传递给视图的渲染功能时,我正在使用此代码为我的把手模板显示名称:
{{#each publications}}
{{#if name}}
<li style='color:green'>
{{name}}
</li>
{{/if}}
{{/each}}
现在我还想要的是在名称按钮旁边,允许我编辑和删除,就像Rails最初生成的视图&gt; publications&gt; index.html.erb页面一样。代码是:
<%= link_to t('.edit', :default => t("helpers.links.edit")),
edit_publication_path(publication), :class => 'btn btn-mini' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
publication_path(publication),
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-mini btn-danger' %>
由于此代码涉及.erb标记,我不知道如何将其集成到我的手柄模板中。有人可以帮我解决这个问题吗?我想要实现的目标是否存在根本性的错误?
答案 0 :(得分:3)
你应该能够将把手模板文件重命名为* .hbs.erb,并且像往常一样使用erb标签。
Rails将按照从右到左的文件扩展名的顺序编译文件。 在这种情况下,erb内容将被注入到手柄文件中,然后就可以了 预编译的服务器端,或发送到客户端并在运行时编译(默认行为)。