在布局中解释 CoffeeScript
我使用 content_for
添加一些视图特定的 .js 代码到页面的标题中,现在
<% content_for :head do %>
<script lang="text/javascript">
$.getJSON("<%= book_chapters_path(@book) %>", function(data){
});
</script>
<% end %>
我如何将该 js 代码切换到 coffescript,我可以放入一个代码块来告诉 Rails 将其转换吗到 javascript,或者甚至只是添加“lang/coffeescript”,然后 Rails 就会处理它。
I am adding some view specific .js code to the header of the page using content_for
like so
<% content_for :head do %>
<script lang="text/javascript">
$.getJSON("<%= book_chapters_path(@book) %>", function(data){
});
</script>
<% end %>
now how would I switch that js code to coffescript, can I put in a code block to tell rails to convert it to javascript, or even just add "lang/coffeescript" and rails would then just handle it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在布局中:
其中
cs/coffee-partial
是views/cs/_coffee-partial.html.coffee
。您甚至可以将局部变量传递给 render 并将它们输出到您的 Coffee-partial 中:
然后:
In layout:
Where
cs/coffee-partial
is aviews/cs/_coffee-partial.html.coffee
.You can even pass local variables to
render
and output them into your coffee-partial:And then:
您可以使用这个 gem: https://github.com/markbates/coffeebeans
You can use this gem: https://github.com/markbates/coffeebeans