TypeError:对象不支持此属性或方法 [英] TypeError: Object doesn't support this property or method
问题描述
我已经创建了Rails应用程序,并在其中创建了一个数据库(空).当我尝试查看产品页面时,在我的 http://localhost:3000/products 上收到以下错误页.在迁移数据库之前,该应用程序已运行.我正在使用therubyracer,并且在Windows 7上.
I have created rails application where I created a database (empty). When I try to view my products page, I receive the following error on my http://localhost:3000/products page. Before migrating the database, the application did function. I am using therubyracer and am on Windows 7.
ExecJS::ProgramError in Products#index
Showing C:/RailsInstaller/DevKit/home/JP/nameofapp/app/views/layouts/application.html.erb where line #16 raised:
TypeError: Object doesn't support this property or method
(in C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/assets/javascripts/turbolinks.js.coffee)
Extracted source (around line #16):
13 <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
14
15 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
16 <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
17 <%= csrf_meta_tags %>
18
19 </head>
Rails.root: C:/RailsInstaller/DevKit/home/JP/nameofapp
这是我在Rails服务器上得到的:
This is what I got on the Rails server:
Started GET "/products" for 127.0.0.1 at 2015-04-23 22:28:06 -0400
ActiveRecord::SchemaMigration Load (0.0ms) SELECT "schema_migrations".* FROM
"schema_migrations"
Processing by ProductsController#index as HTML
Product Load (0.0ms) SELECT "products".* FROM "products"
Rendered products/index.html.erb within layouts/application (4.0ms)
Completed 500 Internal Server Error in 3391ms
ActionView::Template::Error (TypeError: Object doesn't support this property or
method
(in C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/turbolinks-2.5.3/lib/
assets/javascripts/turbolinks.js.coffee)):
13: <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.mi
n.js"></script>
14:
15: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolin
ks-track' => true %>
16: <%= javascript_include_tag 'application', 'data-turbolinks-track' => t
rue %>
17: <%= csrf_meta_tags %>
18:
19: </head>
app/views/layouts/application.html.erb:16:in `_app_views_layouts_application_h
tml_erb__912949727_56715336'
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8
/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8
/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb
(6.0ms)
Rendered C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.1.8
/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within
rescues/layout (27.0ms)
谢谢您的帮助.
推荐答案
发生此错误是因为在找到位于应用程序/资产中的正确资产时存在一些问题.要解决此问题,您可以按照以下步骤操作.
The error occurs because there is some problem finding the correct assets which are located in app/assets. To resolve the issue, you can following below steps.
在Gemfile中添加 gem'coffee-script-source','1.8.0'并运行 bundle install ,然后 运行捆绑更新coffee-script-source 重新启动Rails服务器 还是有一个肮脏的解决方法,可以从中更改代码
Add gem 'coffee-script-source', '1.8.0' into Gemfile and run bundle install then Run bundle update coffee-script-source Restart rails server Or there is a dirty workaround which is to change the code from
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
到
<%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
但是请注意,这种解决方法并不能真正解决应用程序问题,它只会使您的应用程序在没有预期的样式表和JavaScript的情况下正常工作.
But note this workaround doesn't really resolve the application issue, it just makes your application works without expected stylesheets and javascripts.
这篇关于TypeError:对象不支持此属性或方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!