ExecJS::RuntimeError in Users#index (RoR) [英] ExecJS::RuntimeError in Users#index (RoR)

查看:42
本文介绍了ExecJS::RuntimeError in Users#index (RoR)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚运行了生成脚手架用户..."命令.

Just ran a "generate scaffold Users ... " command.

然后我去 localhost:3000/users/ 看到这个:

Then I go to localhost:3000/users/ and see this:

 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'
...

这意味着什么?

更新:

这是在 Windows 8 上.Windows 7 不会出现这些错误.

That's on Windows 8. Windows 7 doesn't give these errors.

推荐答案

几个月前,我的朋友在尝试有关 Win 8 RTM 的 Rails 教程时遇到了这个错误.不确定 Windows 7 中是否也存在此问题,但这可能会有所帮助.

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.

选项:

1) 删除 //= require_tree ./忽略问题 - 这一行首先不应该导致问题.ExecJS 与您系统上的 JavaScript 运行时正常工作存在实际问题,删除这一行只是忽略了这一事实.

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.

2) 安装 Node.js/逃跑 - 许多人似乎只是最终安装了 Node.js 并使用它而不是系统上已有的 JavaScript 运行时.虽然这是一个有效的选项,但它也需要额外的软件,并且只能避免原始问题,即 ExecJS 无法与系统上已有的 JavaScript 运行时正常工作.如果您系统上现有的 JavaScript 运行时应该可以工作,为什么不让它工作而不是安装更多软件呢?根据 ExecJS 创建者的说法,实际上已经支持 Windows 内置的运行时...

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

ExecJS 允许您从 Ruby 运行 JavaScript 代码.它会自动选择可用的最佳运行时来评估您的 JavaScript 程序,然后将结果作为 Ruby 对象返回给您.

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 支持这些运行时:

ExecJS supports these runtimes:

  • therubyracer - 嵌入在 Ruby 中的 Google V8
  • therubyrhino - 嵌入在 JRuby 中的 Mozilla Rhino
  • Node.js
  • Apple JavaScriptCore - 包含在 Mac OS X 中
  • Microsoft Windows 脚本宿主 (JScript)

(来自 github.com/sstephenson/execjs#execjs)

3) 实际解决问题/学习 - 使用选项 1 和 2 的知识来搜索其他解决方案.在实际找到有关我们遇到的根本问题的信息之前,我无法告诉您在看到选项 1 或 2 时我关闭了多少个网页是公认的解决方案.我们一直在寻找的唯一原因是我们无法相信 Rails 团队会 (1) 在导致问题的每个脚手架生成的项目中插入一行代码,或者 (2) 要求我们安装额外的软件来运行默认的代码行.因此,我们最终解决了我们的根本问题(您的里程可能会有所不同).

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).

对我们有用的修复:在有问题的系统上,找到 ExecJS 的 runtimes.rb 文件.它看起来像这个.复制找到的文件以进行备份.打开原始 runtimes.rb 进行编辑.找到以 JScript = ExternalRuntime.new( 行开头的部分.在该部分中,在包含 :command => "cscript//E:jscript//Nologo//U", - 仅删除 //U.然后在包含 :encoding => 'UTF-16LE' # CScript with//U 返回 UTF-16LE - 将 UTF-16LE 更改为 UTF-8 .将更改保存到文件中.文件的这一部分现在应该是:

The Fix that worked for us: On the system having issues, find ExecJS's runtimes.rb file. 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 //U only. 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:

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
)

接下来,停止然后重新启动 Rails 服务器并刷新浏览器中产生原始错误的页面.希望页面现在加载没有错误.这是我们最初发布结果的 ExecJS 问题线程:https://github.com/sstephenson/execjs/issues/81#issuecomment-9892952

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

如果这不能解决问题,您可以随时使用您(希望)制作的备份副本覆盖修改后的 runtimes.rb,一切都会恢复原状.在这种情况下,请考虑选项 3 并继续搜索.让我们知道什么最终对您有用......除非它删除 require_tree 或安装 node.js,否则已经有很多事情发生了.:)

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. :)

这篇关于ExecJS::RuntimeError in Users#index (RoR)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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