How can I call Coffeescript templates in a JBBAR template in JavaScript in jquery_ujs response?

I use the Coffeescript template in my Rails 3.1 application, 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 also use jquery_ujs to respond to PostsController # create and want to use the /views/posts/show.js.erb application to display the response. In show.js.erb, I want to use the template on top. How can I do it? Thanks.

+4
source share
2 answers

It seems that https://github.com/markbates/coffeebeans may be what you are looking for.

+2
source

Use the power of Rails templates. If you rename the file it answers like show.js.coffee.erb (or show.coffee.erb - it doesn’t remember), then what rails the engine template generates .erb code for you, after which it will translate JS coffee, and only after that your client will receive the response text.

It works great with .erb. With .haml, I have some problems ...

0
source

All Articles