Rails coffeescript:TypeError:Object不支持此属性或方法 [英] Rails coffeescript : TypeError: Object doesn't support this property or method

查看:184
本文介绍了Rails coffeescript:TypeError:Object不支持此属性或方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下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不支持此属性或方法
:/Users/mbratc01/Documents/Rails/manpower/app/assets/javascripts/welcome.js.coffee)

提取的来源(第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 的内容是:

 #全部这里的匹配控制器的行为和钩子。 
#所有这些逻辑将在application.js中自动使用。
#您可以在此文件中使用CoffeeScript:http://coffeescript.org/

我发现,如果我只是移动这个文件到另一个,不可访问的位置,应用程序运行正常。此外,在 app / assets / javascript 文件夹中只放置一个空的 .coffee 文件会产生相同的错误。 / p>

我在StackOverflow上看到了一些看起来非常相似的帖子,但是在阅读完这些帖子之后,我找不到问题的根本原因,解决它,而不是摆脱 .coffee 文件。我怀疑这里有一些不太正确的CoffeeScript能力设置,但不知道什么是给出正确的宝石似乎要安装。



任何人都有建议可能是什么原因导致此错误?

解决方案

根据,CoffeeScript在Windows上不能运行得很好。您可能想尝试降低CoffeeScript版本或将其从您的Gemfile中完全删除。



然后只需重命名 .coffee 文件复制到一个简单的 .js 和摇滚常规javascript在你的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

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>

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/

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.

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?

解决方案

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.

Then just rename the .coffee file to a plain .js and rock regular javascript in your Rails app.

这篇关于Rails coffeescript:TypeError:Object不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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