【问题标题】:Rails coffeescript : TypeError: Object doesn't support this property or methodRails coffeescript:TypeError:对象不支持此属性或方法
【发布时间】:2015-05-07 01:52:16
【问题描述】:

我有以下 rails 配置:

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 没有透露任何内容)。我得到的错误是:

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的内容是:

# 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 文件会产生与上述相同的错误。

我在 StackOverflow 上看到了一些看起来非常相似的帖子,但是在阅读完这些帖子后,我找不到问题的根本原因,也无法在不删除 .coffee 的情况下解决它文件。我怀疑这里的 CoffeeScript 功能设置不太正确,但不确定是否安装了正确的 gem。

有人对可能导致此错误的原因提出建议吗?

【问题讨论】:

标签: ruby-on-rails-4 coffeescript


【解决方案1】:

根据this,CoffeeScript 不能很好地与 Windows 配合使用。您可能想尝试降级 CoffeeScript 版本或将其从 Gemfile 中完全删除。

然后只需将 .coffee 文件重命名为纯 .js 并在 Rails 应用程序中使用常规 javascript。

【讨论】:

  • 谢谢。我看到了,我想我正在寻找确认。到现在为止,它一直工作得很好。但我不介意删除它。我还没有真正将它用于这个项目。按照该链接中的建议,将 coffee-script-source 强制转换为 1.8.0 也可以。
  • 这仍然是一个问题,因为客户端的旧版 (3.2.18) Rails 应用程序突然开始做同样的事情。将所有 *.js.coffee 文件重写为常规 *.js 解决了问题。
【解决方案2】:

我认为重命名扩展不是好的解决方案。请尝试以下操作:

添加到 Gemfile

gem 'coffee-script-source', '1.8.0'

然后,运行

bundle update coffee-script-source

并重新启动服务器(如果需要)

【讨论】:

    猜你喜欢
    • 2015-04-03
    • 2013-10-05
    • 1970-01-01
    • 2015-07-02
    • 2019-04-09
    • 2013-03-23
    • 1970-01-01
    相关资源
    最近更新 更多