Ruby-on-rails Pages#home 中的 Rails ExecJS::ProgramError?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28421547/
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
Rails ExecJS::ProgramError in Pages#home?
提问by AB10
Starting a new app, when I create a controller page home and try to go to local host:3000/pages/home, I get the following error:
启动一个新应用程序,当我创建一个控制器页面主页并尝试转到本地主机:3000/pages/home 时,出现以下错误:
Showing c:/Users/Doesha/desktop/pinplug/app/views/layouts/application.html.erb where line #6 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)
application.html.erb file:
application.html.erb 文件:
<!DOCTYPE html>
<html>
<head>
<title>Pinplug</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
application_controller.rb file:
application_controller.rb 文件:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
pages_controller.rb file:
pages_controller.rb 文件:
class PagesController < ApplicationController
def home
end
end
routes.rb file:
route.rb 文件:
Rails.application.routes.draw do
get 'pages/home'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get 'products/:id' => 'catalog#view'
# Example of named route that can be invoked with purchase_url(id: product.id)
# get 'products/:id/purchase' => 'catalog#purchase', as: :purchase
# Example resource route (maps HTTP verbs to controller actions automatically):
# resources :products
# Example resource route with options:
# resources :products do
# member do
# get 'short'
# post 'toggle'
# end
#
# collection do
# get 'sold'
# end
# end
# Example resource route with sub-resources:
# resources :products do
# resources :comments, :sales
# resource :seller
# end
# Example resource route with more complex sub-resources:
# resources :products do
# resources :comments
# resources :sales do
# get 'recent', on: :collection
# end
# end
# Example resource route with concerns:
# concern :toggleable do
# post 'toggle'
# end
# resources :posts, concerns: :toggleable
# resources :photos, concerns: :toggleable
# Example resource route within a namespace:
# namespace :admin do
# # Directs /admin/products/* to Admin::ProductsController
# # (app/controllers/admin/products_controller.rb)
# resources :products
# end
end
gemfile:
宝石文件:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.0'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'execjs', '~> 2.2.2'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gemfile.lock file:
gemfile.lock 文件:
GEM
remote: https://rubygems.org/
specs:
actionmailer (4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 1.0, >= 1.0.5)
actionpack (4.2.0)
actionview (= 4.2.0)
activesupport (= 4.2.0)
rack (~> 1.6.0)
rack-test (~> 0.6.2)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
actionview (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
erubis (~> 2.7.0)
rails-dom-testing (~> 1.0, >= 1.0.5)
rails-html-sanitizer (~> 1.0, >= 1.0.1)
activejob (4.2.0)
activesupport (= 4.2.0)
globalid (>= 0.3.0)
activemodel (4.2.0)
activesupport (= 4.2.0)
builder (~> 3.1)
activerecord (4.2.0)
activemodel (= 4.2.0)
activesupport (= 4.2.0)
arel (~> 6.0)
activesupport (4.2.0)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
arel (6.0.0)
binding_of_caller (0.7.2)
debug_inspector (>= 0.0.1)
builder (3.2.2)
byebug (3.5.1)
columnize (~> 0.8)
debugger-linecache (~> 1.2)
slop (~> 3.6)
coffee-rails (4.1.0)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.0)
coffee-script (2.3.0)
coffee-script-source
execjs
coffee-script-source (1.9.0)
columnize (0.9.0)
debug_inspector (0.0.2)
debugger-linecache (1.2.0)
erubis (2.7.0)
execjs (2.2.2)
globalid (0.3.2)
activesupport (>= 4.1.0)
hike (1.2.3)
i18n (0.7.0)
jbuilder (2.2.6)
activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2)
jquery-rails (4.0.3)
rails-dom-testing (~> 1.0)
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
json (1.8.2)
loofah (2.0.1)
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
mime-types (2.4.3)
mini_portile (0.6.2)
minitest (5.5.1)
multi_json (1.10.1)
nokogiri (1.6.6.2-x86-mingw32)
mini_portile (~> 0.6.0)
rack (1.6.0)
rack-test (0.6.3)
rack (>= 1.0)
rails (4.2.0)
actionmailer (= 4.2.0)
actionpack (= 4.2.0)
actionview (= 4.2.0)
activejob (= 4.2.0)
activemodel (= 4.2.0)
activerecord (= 4.2.0)
activesupport (= 4.2.0)
bundler (>= 1.3.0, < 2.0)
railties (= 4.2.0)
sprockets-rails
rails-deprecated_sanitizer (1.0.3)
activesupport (>= 4.2.0.alpha)
rails-dom-testing (1.0.5)
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6.0)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.1)
loofah (~> 2.0)
railties (4.2.0)
actionpack (= 4.2.0)
activesupport (= 4.2.0)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rake (10.4.2)
rdoc (4.2.0)
json (~> 1.4)
sass (3.4.11)
sass-rails (5.0.1)
railties (>= 4.0.0, < 5.0)
sass (~> 3.1)
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (~> 1.1)
sdoc (0.4.1)
json (~> 1.7, >= 1.7.7)
rdoc (~> 4.0)
slop (3.6.0)
sprockets (2.12.3)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sprockets-rails (2.2.4)
actionpack (>= 3.0)
activesupport (>= 3.0)
sprockets (>= 2.8, < 4.0)
sqlite3 (1.3.10-x86-mingw32)
thor (0.19.1)
thread_safe (0.3.4)
tilt (1.4.1)
turbolinks (2.5.3)
coffee-rails
tzinfo (1.2.2)
thread_safe (~> 0.1)
tzinfo-data (1.2015.1)
tzinfo (>= 1.0.0)
uglifier (2.7.0)
execjs (>= 0.3.0)
json (>= 1.8.0)
web-console (2.0.0)
activemodel (~> 4.0)
binding_of_caller (>= 0.7.2)
railties (~> 4.0)
sprockets-rails (>= 2.0, < 4.0)
PLATFORMS
x86-mingw32
DEPENDENCIES
byebug
coffee-rails (~> 4.1.0)
execjs (~> 2.2.2)
jbuilder (~> 2.0)
jquery-rails
rails (= 4.2.0)
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
sqlite3
turbolinks
tzinfo-data
uglifier (>= 1.3.0)
web-console (~> 2.0)
application.rb file:
application.rb 文件:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Pinplug
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
end
end
I also downgraded the turbolinks gem from 2.3.0 to 2.2.2, thinking that the newer version of the turbolinks gem was causing my app to have errors; obviously that didn't work for me.
我还将 turbolinks gem 从 2.3.0 降级到 2.2.2,认为新版本的 turbolinks gem 导致我的应用程序出错;显然这对我不起作用。
Any suggestions on what could be going wrong with my app?
关于我的应用程序可能出现什么问题的任何建议?
回答by FlyC
In your /app/views/layouts/application.html.erblines 5and 6, change the first parameter from applicationto default.
在您的/app/views/layouts/application.html.erb行5和6 中,将第一个参数从 更改application为default。
I met the same problem, too
for my situation, I don't know why, but it only happens on Windows.
The parameter applicationworks on the web server.
对于我的情况,我也遇到了同样的问题,我不知道为什么,但它只发生在 Windows 上。该参数application适用于 Web 服务器。
回答by evedovelli
If you are running in WIndows, the coffee-script-source 1.9.0 does not work on windows.
如果您在 WINdows 中运行,coffee-script-source 1.9.0 在 Windows 上不起作用。
Change it to a previous version adding this line to your Gemfile:
将其更改为以前的版本,将此行添加到您的 Gemfile 中:
gem 'coffee-script-source', '1.8.0'
And then reinstall the bundle adjusting the dependencies for the new Gem version with:
然后重新安装包,调整新 Gem 版本的依赖项:
bundle update coffee-script-source
回答by MK McKenzie
I've been having this issue for a while and having gone through all the answers in this thread and found them all to be unsuccessful, I've decided to add my solution in hopes that it helps future Rails users.
我遇到这个问题已经有一段时间了,并且浏览了这个线程中的所有答案,发现它们都不成功,我决定添加我的解决方案,希望它可以帮助未来的 Rails 用户。
I've done everything in this thread - changing applicationto defaultallows it to go through without an error, but then once you actually try to use any JavaScript, an error is displayed regarding not being able to find default.js. I've installed NodeJS and put it in my Ruby/bin folder. That did nothing, so I removed it.
我已经在该线程中完成了所有操作 - 更改application为default允许它通过而不会出错,但是一旦您实际尝试使用任何 JavaScript,就会显示一个关于无法找到default.js. 我已经安装了 NodeJS 并将其放在我的 Ruby/bin 文件夹中。那没有任何作用,所以我删除了它。
You can indeed temporarilyget around this problem with the "switching out applicationwith default" solution, but it's extremely short term. This solution may work for you if you have no intention of styling or adding JavaScript to your app through the Rails asset pipeline. I have not tested this myself, but I imagine including JavaScript and stylesheets in the application.html header file may work. But then you lose the magic of Rails.
你确实可以暂时解决这个问题,“切换出application与default解决方案”,但它是非常短期的。如果您不打算通过 Rails 资产管道为您的应用添加样式或添加 JavaScript,则此解决方案可能适合您。我自己没有测试过,但我想在 application.html 头文件中包含 JavaScript 和样式表可能会起作用。但是这样你就失去了 Rails 的魔力。
I have had this issue on Windows 8, Windows 10, and Ubuntu platforms.
我在 Windows 8、Windows 10 和 Ubuntu 平台上遇到过这个问题。
The only thing that solves it, for me, and still renders the JavaScript and stylesheets is to first change applicationto application.cssfor the stylesheets (even if you're using Sass/SCSS, because it still compiles down into css) and application.jsfor the JavaScript link. Once that is done, go into your /assets/javascripts/application.jsfile and delete the //in front of //= require turbolinks.
这解决了它,对我来说,仍然呈现JavaScript和样式表的唯一一件事就是先改变application到application.css的样式表(即使你使用的Sass / SCSS,因为它仍然会编译成CSS)和application.js对JavaScript的链接。一旦做到这一点,进入你的/assets/javascripts/application.js文件,并删除//前面//= require turbolinks。
And now your application should work just fine.
现在您的应用程序应该可以正常工作了。
This is probably a deeper issue with turbolinks, but this is a quick workaround that hasn't let me down yet.
这可能是 turbolinks 的一个更深层次的问题,但这是一个快速的解决方法,还没有让我失望。
回答by Thorin
in windows coffee-script source >= 1.9.0 not work properly. just add in Gemfile
在 windows 咖啡脚本源 >= 1.9.0 不能正常工作。只需添加 Gemfile
gem 'coffee-script-source', '1.8.0'
and run
并运行
bundle update coffee-script-source
回答by Ilya Bodrov-Krukowski
Just install NodeJS on your local machine (make sure the correspodning entry is added to the PATH) and add
只需在本地机器上安装 NodeJS(确保将相应条目添加到 PATH)并添加
gem 'execjs'
into the Gemfile.
进入Gemfile。
回答by Paul Leach
On windows 10 version 1511, adding gem 'coffee-script-source', '1.8.0' to my gemfile and then ruby bin\bundle update coffee-script-source from the project directory worked. NB: the previous coffee-script-source version that got replaced was 1.10.0
在 Windows 10 版本 1511 上,将 gem 'coffee-script-source', '1.8.0' 添加到我的 gemfile 中,然后 ruby bin\bundle update coffee-script-source 从项目目录工作。注意:之前被替换的 coffee-script-source 版本是 1.10.0
回答by adhix11
(On Windows 8)
(在 Windows 8 上)
- Install Node.js!
- Add it to the PATH (ENV_VAR)
- restart the server
- 安装 Node.js!
- 将其添加到 PATH (ENV_VAR)
- 重启服务器
回答by dmers
I had this issue too. I went into Sublime into my project folder. Then clicked the app folders, view folder, layout, clicked application.html.erb and changed lines 5 and 6 'application' to 'default'. Worked great. Thanks for posting your problem and thank you to those that answered!
我也有这个问题。我进入 Sublime 进入我的项目文件夹。然后单击应用程序文件夹,查看文件夹,布局,单击 application.html.erb 并将第 5 行和第 6 行“应用程序”更改为“默认”。工作得很好。感谢您发布您的问题,并感谢那些回答的人!
I just wanted to add I went in through Sublime. I am just learning and I didn't understand how to access the .erb file. Just wanted to help others.
我只是想补充一下,我是通过 Sublime 进入的。我只是在学习,我不明白如何访问 .erb 文件。只是想帮助别人。
回答by Rpant
Finally got it working what a sigh of relief. Even though I am not exactly sure what made it work. Tried all of the following. 1) Installed node.js , added coffescript npm to it, and restarted. 2) Added gem for exec.js and modified runtime.rb so that it is not able to use default windows script file. Refer to this link on how to do this: [https://github.com/sstephenson/execjs/issues/81][1]3) To be safe, also added rubyracer gem gem 'therubyracer', platforms: :ruby
终于搞定了,真是松了一口气。尽管我不确定是什么让它起作用。尝试了以下所有方法。1) 安装 node.js ,添加 coffescript npm 并重启。2) 为 exec.js 添加 gem 并修改 runtime.rb 使其无法使用默认的 windows 脚本文件。请参阅此链接以了解如何执行此操作:[ https://github.com/sstephenson/execjs/issues/81][1]3) 为安全起见,还添加了 rubyracer gem gem 'therubyracer',平台::ruby
In summary added two scripting engines , nodejs and rubyracer and added execjs so that it chooses the best scripting engine , but is not able to choose windows scrpting engine.
总之添加了两个脚本引擎,nodejs 和rubyracer 并添加了execjs 以便它选择最好的脚本引擎,但不能选择windows 脚本引擎。
I guess just installing nodejs alone might have worked after adding execjs. However I did not restart(post nodejs installation) and tried all the other things.
我想在添加 execjs 后,单独安装 nodejs 可能会起作用。但是我没有重新启动(安装 nodejs 后)并尝试了所有其他的东西。
回答by Kaz
I am on Rails 5.1.6. I had the same issue. As recommended above I degraded the coffee-script-source gem which solved the issue.
我在 Rails 5.1.6 上。我遇到过同样的问题。如上所述,我降级了解决问题的咖啡脚本源 gem。
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2' # <-- This existed already
gem 'coffee-script-source', '1.8.0' # <-- Adding this line solved the problem
Note: I didn't modify application.html.rb file
注意:我没有修改 application.html.rb 文件

