Ruby-on-rails 类型错误:对象不支持此属性或方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29838237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: Object doesn't support this property or method
提问by user4808012
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/productspage. Before migrating the database, the application did function. I am using therubyracer and am on Windows 7.
我创建了 rails 应用程序,在其中创建了一个数据库(空)。当我尝试查看我的产品页面时,我在http://localhost:3000/products页面上收到以下错误。在迁移数据库之前,应用程序运行。我正在使用 therubyracer 并且在 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
This is what I got on the Rails server:
这是我在 Rails 服务器上得到的:
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)
Thank you for any help.
感谢您的任何帮助。
回答by Naiguel Developer
I removed the require_tree from application.js and it worked
我从 application.js 中删除了 require_tree 并且它起作用了
//= require jquery
//= require jquery_ujs
//= require turbolinks
// require_tree .
回答by Alok Amme
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.
发生该错误是因为找到位于 app/assets 中的正确资产存在一些问题。要解决此问题,您可以按照以下步骤操作。
Add gem 'coffee-script-source', '1.8.0'into Gemfile and run bundle installthen Run bundle update coffee-script-sourceRestart rails server Or there is a dirty workaround which is to change the code from
将gem 'coffee-script-source', '1.8.0' 添加到 Gemfile 并运行bundle install然后运行bundle update coffee-script-source重新启动 rails server 或者有一个肮脏的解决方法是将代码从
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
to
到
<%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
But note this workaround doesn't really resolve the application issue, it just makes your application works without expected stylesheets and javascripts.
但请注意,此解决方法并不能真正解决应用程序问题,它只会让您的应用程序在没有预期样式表和 javascript 的情况下工作。
回答by Hansa Tharuka
I think Best Solution is Removing the slashes in application.js file like
我认为最好的解决方案是删除 application.js 文件中的斜杠,例如
= require jquery
= require jquery_ujs
= require turbolinks
= require_tree .
回答by Opy Osegs
I had this issue too, checkout the extensive solution on this thread, ExecJS::RuntimeError on Windows trying to follow rubytutorialby @Kevin P. Also,the solution by, @evedoevelli, on another thread: Rails ExecJS::ProgramError in Pages#home?works. I used the second solution with it been the most recent date-wise.
我也有这个问题,请查看此线程上的广泛解决方案, Windows 上的 ExecJS::RuntimeError 试图遵循@Kevin P 的 rubytutorial。此外,@evedoevelli 在另一个线程上的解决方案:Rails ExecJS::ProgramError in Pages#家?作品。我使用了第二个解决方案,它是最新的日期。
回答by nik
For me,solution was to remove-
对我来说,解决方案是删除-
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'%>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
from
从
app\views\layout\application.html.erb
应用\视图\布局\application.html.erb
回答by Ralphkay
Upon careful research this is the solution I stumbled upon. Just make sure you have the latest version of NodeJsinstalled. After installing NodeJs, make sure you restart our system. However it is very important that you update your windows OS. You should be fine. If you are using RubyMineeverything should work by now. No need to be troubling your head over the coffee-script issue. The ExecJs Program error seem to be more related to the NodeJs and its associated modules.
经过仔细研究,这是我偶然发现的解决方案。只需确保您安装了最新版本的NodeJs。安装 NodeJs 后,请确保重新启动我们的系统。但是,更新 Windows 操作系统非常重要。你应该没事。如果您正在使用RubyMine,那么现在一切都应该可以工作了。无需为咖啡脚本问题而烦恼。ExecJs 程序错误似乎与 NodeJs 及其相关模块更相关。
回答by Mckay Smalley
The reason is because NodeJSis not installed. If you install it, the problem should go away.
原因是没有安装NodeJS。如果您安装它,问题应该会消失。
However, this would work as well in application.js:
但是,这也适用于application.js:
//= require jquery
//= require jquery_ujs
//= require turbolinks
// require_tree .
But this is just not the prefered method because all this does is disable rails functionality. For example, ActionCable will not work with this change.
但这并不是首选方法,因为所有这些都是禁用 rails 功能。例如,ActionCable 不适用于此更改。
回答by Mahan Lamei
If you do not use layouts, put "layout false" in the controller file, just below class title:
如果您不使用布局,请将“layout false”放在控制器文件中,就在类标题下方:
class ABCController < ApplicationController "layout false" def index ... ..
class ABCController < ApplicationController "layout false" def index ... ..

