开发者

How do I call Coffeescript templates in a Javascript ERB template in a jquery_ujs response?

I am using Coffeescript template in my Rails 3.1 app, so in my app/assets/javascripts/post.js.coffee file, I have something like:

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

where post is a JSON object. The template is in app/assets/javascripts/templates/posts/show

Now I am also using jquery_ujs to respond to PostsController#create and want to use app/views/posts/show.js.erb to render a response. In show.js.erb, I want to use the template from开发者_开发知识库 above. How would I go about doing that? Thanks.


Seems like https://github.com/markbates/coffeebeans might be what you are looking for.


Use power of Rails templates. If you rename your respond file as show.js.coffee.erb (or show.coffee.erb - don't remember) you than rails template engine generates for you .erb code, after that it will translate coffee to js, and only after that your client will gain the response text.

With .erb it works fine. With .haml I have some problems...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜