如何在应用程序/视图中呈现new.js.coffee.erb? [英] How to render new.js.coffee.erb in app/views?

查看:82
本文介绍了如何在应用程序/视图中呈现new.js.coffee.erb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Rails 3.1 jquery_ujs,我有一个与:remote => true的链接,并且控制器new动作使用js进行响应并呈现包含以下内容的new.js.erb:

Using Rails 3.1 jquery_ujs, I have a link with :remote => true, and the controller new action responds with js and render new.js.erb which contains:

$('#post-form').html('<%= escape_javascript(render(:partial => "form")) %>');

它将呈现_form.html.erb部分.这行得通.

It renders the _form.html.erb partial. This works.

现在我想使用Coffeescript,但是将new.js.erb重命名为new.js.coffee.erb不起作用.资产管道仅在应用程序/资产中工作吗?我究竟做错了什么?谢谢.

Now I want to use Coffeescript, but renaming new.js.erb to new.js.coffee.erb doesn't work. Does the asset pipeline only work in app/assets? What am I doing wrong? Thanks.

推荐答案

我在使用Rails 3.1.0时遇到了同样的问题.尝试将文件重命名为new.js.coffee.尽管文件名没有扩展名,它仍应呈现erb.

I had this same issue using Rails 3.1.0. Try renaming your file to just new.js.coffee. It should still render erb despite not having the extension on the filename.

视图模板没有遵循与资产管道相同的约定,这确实令人困惑.

It's definitely confusing that view templates don't follow the same conventions as the asset pipeline.

这篇关于如何在应用程序/视图中呈现new.js.coffee.erb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆