简体   繁体   English

骨干JST模板,如何渲染Rails部分

[英]Backbone JST Template, How to Render Rails Partials

A couple of select elements in my JST Template rely on the db to populate choices. 我的JST模板中的几个select元素依赖于db来填充选择。 Can I pull a rails partial into my template? 我可以将部分护栏拉入模板吗? What is the best way to do this? 做这个的最好方式是什么?

For example a partial like this: 例如这样的部分:

_font_faces.html.haml _font_faces.html.haml

.font_face
  = select("font", "style", Font.all.collect {|f| [ f.name, f.id ] })

The answer to this question is, you don't want to put that kind of logic into your view anyways. 这个问题的答案是,无论如何,您都不想在您的视图中加入这种逻辑。 There should be a separate backbone collection made, a font collection, not a call to the db in the view. 应该有一个单独的主干集合,一个字体集合,而不是视图中对数据库的调用。

If you name something like choices.jst.eco.haml the asset pipeline will compile the file going backwards from the file extension. 如果您使用choices.jst.eco.haml之类的名称命名,资产管道将编译从文件扩展名开始向后的文件。 So, the HAML compiler will run first, then the ECO compiler, then the JST gem will throw all that compiled code into the JST object that you can reference in your view. 因此,将先运行HAML编译器,然后运行ECO编译器,然后运行JST gem,然后将所有已编译的代码扔到您可以在视图中引用的JST对象中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM