带有rails 3.1的咖啡脚本中的erb [英] erb in coffee script with rails 3.1

查看:18
本文介绍了带有rails 3.1的咖啡脚本中的erb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的 .coffee 文件中使用一些 erb,如下例所示

I would like to use some erb in my .coffee files, like the following example

myLatlng: new google.maps.LatLng(<%=@location.latitude %>, <%=@location.longitude %>)

我将我的 locations.js.coffee 重命名为 locations.erb.coffee

I renamed my locations.js.coffee to locations.erb.coffee

但我仍然收到以下错误

Error compiling asset application.js:
ExecJS::ProgramError: Error: Parse error on line 4: Unexpected 'COMPARE'
  (in /Users/denisjacquemin/Documents/code/projects/geolog/app/assets/javascripts/locations.erb.coffee)
Served asset /application.js - 500 Internal Server Error

推荐答案

如果您想在您的 VIEW 文件夹中的 .coffee 文件中使用 erb,请将您的文件命名为 yourfilename.js.咖啡,Rails 仍然会处理 ERB,这很奇怪.

If you want erb in the .coffee files IN YOUR VIEW folder, leave your file named as yourfilename.js.coffee, and Rails will still process the ERB, oddly enough.

要使其在 Heroku 中工作,请将 coffee-rails 从 Gemfile 中的资产组中移出.

To make it work in Heroku, move coffee-rails out of the assets group in your Gemfile.

这篇关于带有rails 3.1的咖啡脚本中的erb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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