5

我创建了 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

这是我在 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)

感谢您的任何帮助。

4

8 回答 8

9

发生该错误是因为在查找位于 app/assets 中的正确资产时存在一些问题。要解决此问题,您可以按照以下步骤操作。

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 %>

<%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "default", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>

但请注意,此解决方法并不能真正解决应用程序问题,它只是让您的应用程序在没有预期的样式表和 javascript 的情况下工作。

于 2017-11-05T06:25:09.333 回答
8

我从 application.js 中删除了 require_tree 并且它有效

//= require jquery 
//= require jquery_ujs 
//= require turbolinks 
// require_tree .
于 2017-03-03T17:46:52.090 回答
5

我认为最好的解决方案是删除 application.js 文件中的斜杠,例如

= require jquery
= require jquery_ujs
= require turbolinks
= require_tree .
于 2018-04-23T16:03:53.920 回答
3

我也遇到了这个问题,请查看此线程上的广泛解决方案, ExecJS::RuntimeError on Windows 试图遵循@Kevin P 的 ruby​​tutorial。此外,@evedoevelli 在另一个线程上的解决方案:Rails ExecJS::ProgramError in Pages#家?作品。我使用了第二个解决方案,它是最新的日期。

于 2015-07-16T04:05:06.750 回答
2

经过仔细研究,这是我偶然发现的解决方案。只需确保您安装了最新版本的NodeJs。安装 NodeJs 后,请确保您重新启动我们的系统。但是,更新 Windows 操作系统非常重要。你应该没事。如果您使用的是RubyMine,那么现在一切都应该正常了。无需为咖啡脚本问题烦恼。ExecJs 程序错误似乎与 NodeJs 及其相关模块更相关。

于 2017-02-14T12:15:26.427 回答
2

对我来说,解决方案是删除-

 <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload'%>
 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>

app\views\layout\application.html.erb

于 2018-08-02T07:25:23.677 回答
0

The reason is because NodeJS is not installed. If you install it, the problem should go away.

However, this would work as well in 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.

于 2018-02-13T16:58:58.227 回答
0

如果您不使用布局,请将“layout false”放在控制器文件中,就在类标题下方:

类 ABCController < ApplicationController "layout false" def index ... ..

于 2019-10-11T07:48:59.410 回答