4

我在我的 Rails 3.1 应用程序中使用Coffeescript 模板,所以在我的 app/assets/javascripts/post.js.coffee 文件中,我有类似的内容:

$('#post').html JST['templates/posts/show'] post: post

其中 post 是一个 JSON 对象。模板位于 app/assets/javascripts/templates/posts/show

现在我也在使用 jquery_ujs 来响应 PostsController#create 并希望使用 app/views/posts/show.js.erb 来呈现响应。在 show.js.erb 中,我想使用上面的模板。我该怎么做呢?谢谢。

4

2 回答 2

2

似乎https://github.com/markbates/coffeebeans可能是您正在寻找的东西。

于 2011-10-13T16:16:04.853 回答
0

使用 Rails 模板的强大功能。如果您将您的响应文件重命名为 show.js.coffee.erb(或 show.coffee.erb - 不记得),那么 Rails 模板引擎会为您生成 .erb 代码,之后它会将咖啡转换为 js,并且仅之后,您的客户将获得响应文本。

使用 .erb 可以正常工作。使用 .haml 我有一些问题......

于 2011-10-29T22:12:40.580 回答