如何在 JST 文件中使用 Ruby 代码?
我正在使用 Jammit 来打包我的资产。它做得很好的事情之一就是打包带有 .jst 扩展名的文件,并使它们在浏览器中的 window.jst 命名空间中可用。但是,我一直在寻找一种使这些模板动态化的方法,但我不确定如何做到这一点,或者是否可能。
如果无法使 JST 文件动态化,我有哪些替代方案?
I am using Jammit to package my assets. One of the things it does well is package files with .jst extension and make them available in window.jst namespace in the browser. However, I've been looking for a way to make those templates dynamic, and I'm not sure how to do that or if it's even possible.
What alternatives do I have if I cannot make JST files dynamic?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知,Rails 3.0 是不可能的。 Jammit 假定 JST 文件是 JavaScript 文件。也许在以后的版本中他们可能会添加该功能。但我不指望它会很快发生。
如果您能够升级到 Rails 3.1,您可以用 Asset Pipeline 替换 Jammit,这样您就可以通过 ERB 或您想要的任何语言运行它,然后它最终会成为 JST 文件。
Kliment Mamykin 演示了如何在启用 Asset Pipeline 的情况下从 Rails 3.0 升级到 Rails 3.1.rc4。
http://mamykin.com/2011/07/03/upgrading -to-rails31-rc4.html
As far as I can tell with Rails 3.0 it isn't possible. Jammit assumes the JST files are JavaScript files. Maybe in later versions they may add the ability. But I wouldn't count on it happening any time soon.
If you are able to upgrade to Rails 3.1 you can replace Jammit with the Asset Pipeline that allows you to run it through ERB or what ever language you want before it ends up as a JST file.
Kliment Mamykin made a walkthrough to upgrade from Rails 3.0 to Rails 3.1.rc4 with Asset Pipeline enabled.
http://mamykin.com/2011/07/03/upgrading-to-rails31-rc4.html