Ruby-on-rails ExecJS::RuntimeError in Users#index (RoR)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13530042/
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
ExecJS::RuntimeError in Users#index (RoR)
提问by user1837021
Just ran a "generate scaffold Users ... " command.
刚刚运行了一个“生成脚手架用户......”命令。
Then I go to localhost:3000/users/and see this:
然后我去localhost:3000/users/看看这个:
ExecJS::RuntimeError in Users#index
Showing C:/Users/TheOnlyUser/Desktop/NMS/nms2/app/views/layouts/application.html.erb where line #6 raised:
(in C:/Users/TheOnlyUser/Desktop/NMS/nms2/app/assets/javascripts/ads.js.coffee)
Extracted source (around line #6):
3: <head>
4: <title>Nms2</title>
5: <%= stylesheet_link_tag "application", :media => "all" %>
6: <%= javascript_include_tag "application" %>
7: <%= csrf_meta_tags %>
8: </head>
9: <body>
Rails.root: C:/Users/TheOnlyUser/Desktop/NMS/nms2
Application Trace | Framework Trace | Full Trace
app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb___753556572_43068540'
app/controllers/users_controller.rb:7:in `index'
...
What does that all mean?
这一切意味着什么?
UPDATE:
更新:
That's on Windows 8. Windows 7 doesn't give these errors.
这是在 Windows 8 上。Windows 7 不会出现这些错误。
回答by Kevin P
My friend was attempting a Rails tutorial on Win 8 RTM a few months ago and ran into this error. Not sure if this issue exists in Windows 7 as well, but this may help.
几个月前,我的朋友在 Win 8 RTM 上尝试 Rails 教程时遇到了这个错误。不确定 Windows 7 中是否也存在此问题,但这可能会有所帮助。
Options:
选项:
1) Removing //= require_tree ./ Ignoring the issue -This line should not be causing an issue in the first place. There is an actual problem with ExecJS working properly with the JavaScript runtime on your system and removing this line is just ignoring that fact.
1) 删除 //= require_tree ./忽略问题 -此行首先不应引起问题。ExecJS 与您系统上的 JavaScript 运行时正常工作存在实际问题,删除此行只是忽略了这一事实。
2) Installing Node.js / Running away -Many people seem to just end up installing Node.js and using that instead of the JavaScript runtime already on their system. While that is a valid option, it also requires additional software and only avoids the original issue, which is that ExecJS is not working properly with the JavaScript runtime already on your system. If the existing JavaScript runtime on your system is supposed to work, why not make it work instead of installing more software? According to the ExecJS creator, the runtime already built into Windows is in fact supported...
2) 安装 Node.js / 逃跑 -许多人似乎只是最终安装了 Node.js 并使用它而不是他们系统上已有的 JavaScript 运行时。虽然这是一个有效的选项,但它也需要额外的软件,并且只能避免原始问题,即 ExecJS 无法与系统上已有的 JavaScript 运行时正常工作。如果您系统上现有的 JavaScript 运行时应该可以工作,为什么不让它工作而不是安装更多软件呢?根据 ExecJS 创建者的说法,实际上已经支持 Windows 内置的运行时......
ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program, then returns the result to you as a Ruby object.
ExecJS supports these runtimes:
- therubyracer - Google V8 embedded within Ruby
- therubyrhino - Mozilla Rhino embedded within JRuby
- Node.js
- Apple JavaScriptCore - Included with Mac OS X
- Microsoft Windows Script Host (JScript)
ExecJS 允许您从 Ruby 运行 JavaScript 代码。它会自动选择可用的最佳运行时来评估您的 JavaScript 程序,然后将结果作为 Ruby 对象返回给您。
ExecJS 支持这些运行时:
- therubyracer - 嵌入在 Ruby 中的 Google V8
- therubyrhino - 嵌入在 JRuby 中的 Mozilla Rhino
- 节点.js
- Apple JavaScriptCore - 包含在 Mac OS X 中
- Microsoft Windows 脚本宿主 (JScript)
3) Actually fixing the issue / Learning -Use the knowledge of options 1 and 2 to search for other solutions. I can't tell you how many webpages I closed upon seeing options 1 or 2 was the accepted solution before actually finding information about the root issue we were having. The only reason we kept looking was that we couldn't believe the Rails team would (1) insert a line of code in every scaffold generated project that caused an issue, or (2) require that we install additional software just to run that default line of code. And so we eventually arrived at a fix for our root issue (your miles may vary).
3) 实际解决问题/学习 -使用选项 1 和 2 的知识来搜索其他解决方案。在实际找到有关我们遇到的根本问题的信息之前,我无法告诉您在看到选项 1 或 2 时我关闭了多少个网页是公认的解决方案。我们一直在寻找的唯一原因是我们无法相信 Rails 团队会 (1) 在导致问题的每个脚手架生成的项目中插入一行代码,或者 (2) 要求我们安装额外的软件来运行默认的代码行。所以我们最终解决了我们的根本问题(您的里程可能会有所不同)。
The Fix that worked for us:On the system having issues, find ExecJS's runtimes.rbfile. It looks like this. Make a copy of the found file for backup. Open the original runtimes.rb for editing. Find the section that starts with the line JScript = ExternalRuntime.new(. In that section, on the line containing :command => "cscript //E:jscript //Nologo //U",- remove the //Uonly. Then on the line containing :encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE- change UTF-16LE to UTF-8. Save the changes to the file. This section of the file should now read:
对我们有用的修复:在有问题的系统上,找到 ExecJS 的runtimes.rb文件。看起来像这样。复制找到的文件以进行备份。打开原始 runtimes.rb 进行编辑。找到以行开头的部分JScript = ExternalRuntime.new(。在该部分中,在包含:command => "cscript //E:jscript //Nologo //U",- 删除//U唯一的行上。然后在包含的行上:encoding => 'UTF-16LE' # CScript with //U returns UTF-16LE- 将 UTF-16LE 更改为UTF-8. 保存对文件的更改。文件的这一部分现在应该是:
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-8' # CScript with //U returns UTF-16LE
)
Next, stop then restart your Rails server and refresh the page in your browser that produced the original error. Hopefully the page loads without error now. Here's the ExecJS issue thread where we originally posted our results: https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952
接下来,停止然后重新启动 Rails 服务器并刷新浏览器中产生原始错误的页面。希望页面现在加载没有错误。这是我们最初发布结果的 ExecJS 问题线程:https: //github.com/sstephenson/execjs/issues/81#issuecomment-9892952
If this did not fix the issue, you can always overwrite the modified runtimes.rb with the backup copy you (hopefully) made and everything will be back to square one. In that case, consider option 3 and keep searching. Let us know what eventually works for you.. unless it's removing the require_tree or installing node.js, there's plenty of that going around already. :)
如果这不能解决问题,您可以随时使用您(希望)制作的备份副本覆盖修改后的 runtimes.rb,一切都将恢复原状。在这种情况下,请考虑选项 3 并继续搜索。让我们知道什么最终对您有用......除非它删除 require_tree 或安装 node.js,否则已经有很多事情发生了。:)
回答by agmcleod
Like the commenters said, you're probably missing a gem. Try adding the following to your gemfile:
就像评论者所说的那样,您可能错过了一颗宝石。尝试将以下内容添加到您的 gemfile:
gem 'therubyracer'
And run bundle install
并运行 bundle install
回答by JanuskaE
I initially went for solution 3 above by Kevin P and everything was working fine on my Windows 8 machine.
我最初选择了 Kevin P 上面的解决方案 3,在我的 Windows 8 机器上一切正常。
After a MS update last night (8/19/13) I couldn't even render the homepage in my rails app.
在昨晚 (8/19/13) 进行 MS 更新后,我什至无法在我的 Rails 应用程序中呈现主页。
I installed node.js and it worked so I'm using solution 2 now.
我安装了 node.js 并且它工作正常,所以我现在使用解决方案 2。
回答by user3122977
Editing runtimes.rb solved the problem on Win 8.1
编辑 runtimes.rb 解决了 Win 8.1 上的问题
回答by Hammad
The quikest way to solve the problem is Installing the Node.js. Ruby would detect it automatically and You will have no more JS runtime errors
解决问题的最快方法是安装 Node.js。Ruby 会自动检测它,您将不再有 JS 运行时错误
回答by Hammad
I had the same problem, and solution 3 by Kevin P worked for me (editing the runtimes.rb file).
My setup at time of applying solution is as follows:
OS:Windows 8.1
Ruby version:1.9.3p484
Rails version:3.2.14
我遇到了同样的问题,Kevin P 的解决方案 3 对我有用(编辑 runtimes.rb 文件)。
我在应用解决方案时的设置如下:
操作系统:Windows 8.1
Ruby 版本:1.9.3p484
Rails 版本:3.2.14
回答by Hammad
The fastest way I fixed this issue was this:
我解决这个问题的最快方法是这样的:
gem 'therubyracer', '0.12.1'
宝石 'therubyracer', '0.12.1'
bundle update
捆绑更新
bundle install
捆绑安装
I hope this will help.
我希望这将有所帮助。
回答by user2943905
runtimes.rb file
运行时.rb文件
JScript = ExternalRuntime.new(
:name => "JScript",
:command => "cscript //E:jscript //Nologo",
:runner_path => ExecJS.root + "/support/jscript_runner.js",
:encoding => 'UTF-8' # CScript with //U returns UTF-16LE
)
Working in Windows 8.1
在 Windows 8.1 中工作

