【发布时间】:2014-03-11 17:39:02
【问题描述】:
我正在构建一个使用 Backbone 作为前端框架的 Rails 应用程序。我正在使用 Handlebars 作为模板。
在 Rails 方面,我有一个出版物模型,每个出版物都有很多文章。现在我想将我的出版物名称列表打印到屏幕上。
当我将我的出版物集合传递给视图的渲染函数时,我可以使用此代码为我的车把模板很好地显示名称:
{{#each publications}}
{{#if name}}
<li style='color:green'>
{{name}}
</li>
{{/if}}
{{/each}}
现在我还想要在名称按钮旁边有一个允许我编辑和删除的按钮,就像在 Rails 最初生成的视图 >publications>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 标签,我不知道如何将其集成到我的车把模板中。有人可以帮我解决这个问题吗?我想要完成的工作是否存在根本性错误?
【问题讨论】:
标签: ruby-on-rails templates backbone.js handlebars.js erb