Rails coffeescript:TypeError:对象不支持此属性或方法 [英] Rails coffeescript : TypeError: Object doesn't support this property or method
问题描述
我有以下 rails 配置:
I have the following rails configuration:
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?
推荐答案
根据 this,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 coffeescript:TypeError:对象不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!