Rails 咖啡脚本:类型错误:对象不支持此属性或方法 [英] Rails coffeescript : TypeError: Object doesn't support this property or method
问题描述
我有以下导轨配置:
Windows 7
Rails 4.1.1
Ruby 2.0.0p481
Gem: coffee-rails 4.0.1
Gem: coffee-script 2.3.0
Gem: coffee-script-source 1.9.1
我有一个运行良好的应用程序,但现在不行了.我不记得有什么改变(git diff
没有透露任何东西).我得到的错误是:
I have an application that was working fine, but now doesn't. I don't recall changing anything (git diff
doesn't reveal anything). The error I'm getting is:
TypeError: Object doesn't support this property or method
(in c:/Users/mbratc01/Documents/Rails/manpower/app/assets/javascripts/welcome.js.coffee)
Extracted source (around line #9):
7 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => false %>
8 <%= javascript_include_tag 'jquery-1.11.1', 'data-turbolinks-track' => false %>
9 <%= javascript_include_tag 'application', 'data-turbolinks-track' => false %>
10 <%= csrf_meta_tags %>
11 </head>
我真的没有任何关于 Coffeescript 的项目.welcome.js.coffee
的内容是:
I really have no Coffeescript items going on yet. The contents of welcome.js.coffee
are:
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
我发现如果我只是将这个文件移动到另一个无法访问的位置,应用程序运行良好.此外,在 app/assets/javascript
文件夹中放置一个空的 .coffee
文件会产生上述相同的错误.
I found that if I just move this file to another, inaccessible location, the application runs fine. Also, putting just an empty .coffee
file in the app/assets/javascript
folder generates the same error above.
我在 StackOverflow 上看到了几篇看起来非常相似的帖子,但是在阅读它们之后,我找不到问题的根本原因,也无法在不去掉 的情况下解决它.coffee
文件.我怀疑这里的 CoffeeScript 功能设置有些不太正确,但不确定是否安装了正确的 gem.
I've seen a couple of posts here on StackOverflow that looked very similar, but after reading through them, I couldn't find the root cause of my problem nor could I resolve it without just getting rid of the .coffee
file. I suspect there's something not quite right with the CoffeeScript capability setup here, but not sure what that is given that the right gems appear to be installed.
有人对可能导致此错误的原因有任何建议吗?
Anyone have a suggestion on what could be causing this error?
推荐答案
根据 这个,CoffeeScript 在 Windows 上运行得不好.您可能想尝试降级 CoffeeScript 的版本或将其从 Gemfile 中完全删除.
According tho this, CoffeeScript doesn't play well with Windows. You may want to try downgrading the version of CoffeeScript or completely removing it from your Gemfile.
然后只需将 .coffee
文件重命名为普通的 .js
并在您的 Rails 应用程序中运行常规 javascript.
Then just rename the .coffee
file to a plain .js
and rock regular javascript in your Rails app.
这篇关于Rails 咖啡脚本:类型错误:对象不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!