Pages # home의 Rails ExecJS :: ProgramError?
새 앱을 시작하고 컨트롤러 페이지 홈을 만들고 로컬 host : 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 파일 :
<!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 파일 :
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 파일 :
class PagesController < ApplicationController
def home
end
end
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 파일 :
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 파일 :
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
나는 또한 turbolinks gem을 2.3.0에서 2.2.2로 다운 그레이드했는데, 새로운 버전의 turbolinks gem이 내 앱에 오류를 일으킨다 고 생각했습니다. 분명히 그것은 나를 위해 작동하지 않았습니다.
내 앱에 어떤 문제가 발생할 수 있는지에 대한 제안이 있습니까?
당신에 /app/views/layouts/application.html.erb 선 5 와 6 에서 첫 번째 매개 변수를 변경 application
하는 default
.
내 상황에서도 같은 문제가 발생했습니다. 이유는 모르겠지만 Windows에서만 발생합니다. 매개 변수 application
는 웹 서버에서 작동합니다.
WIndows에서 실행중인 경우 coffee-script-source 1.9.0이 Windows에서 작동하지 않습니다.
Gemfile에 다음 줄을 추가하여 이전 버전으로 변경하십시오.
gem 'coffee-script-source', '1.8.0'
그런 다음 다음을 사용하여 새 Gem 버전에 대한 종속성을 조정하는 번들을 다시 설치합니다.
bundle update coffee-script-source
나는 한동안이 문제를 겪어 왔으며이 스레드의 모든 답변을 검토하고 모두 실패한 것으로 나타났습니다. 미래의 Rails 사용자에게 도움이되기를 바라면서 솔루션을 추가하기로 결정했습니다.
I've done everything in this thread - changing application
to default
allows 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.
You can indeed temporarily get around this problem with the "switching out application
with 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.
Windows 8, Windows 10 및 Ubuntu 플랫폼에서이 문제가 발생했습니다.
해결할 수있는 문제는, 나를 위해, 아직도 자바 스크립트와 스타일 시트를 렌더링하는 유일한 것은 첫 번째 변경이다 application
에 application.css
(여전히 CSS를 아래로 컴파일 때문에, 말대꾸 / SCSS를 사용하는 경우에도) 스타일 시트 및 application.js
자바 스크립트 링크. 이 작업이 완료되면, 당신에 들어갈 /assets/javascripts/application.js
파일과 삭제 //
의 앞에 //= require turbolinks
.
이제 응용 프로그램이 제대로 작동합니다.
이것은 아마도 터보 링크의 더 깊은 문제 일 것입니다. 그러나 이것은 아직 저를 실망시키지 않은 빠른 해결 방법입니다.
Windows 커피 스크립트 소스> = 1.9.0에서 제대로 작동하지 않습니다. Gemfile에 추가하기 만하면됩니다.
gem 'coffee-script-source', '1.8.0'
그리고 실행
bundle update coffee-script-source
로컬 머신에 NodeJS를 설치하고 (해당 항목이 PATH에 추가되었는지 확인) 추가하십시오.
gem 'execjs'
에 Gemfile .
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
(On Windows 8)
- Install Node.js!
- Add it to the PATH (ENV_VAR)
- restart the server
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!
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.
I just changed the 'application
' to 'default
' on lines 5 and 6, and resolved. /app/views/layouts/application.html.erb
.
FROM:
<%= stylesheet_link_tag '**application**', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag '**application**', 'data-turbolinks-track' => true %>
TO:
<%= stylesheet_link_tag '**default**', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag '**default**', 'data-turbolinks-track' => true %>
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
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.
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.
I tried all of the solutions above, and the only one that worked properly was to install node.js, add the directory to the 'path' environment variable in windows (found in Advanced System Settings, Envirnment Variables, path) and then restart the computer and server. I think the later versions of coffee-script-source must be dependent on node.js, along with other gems. I had the identical error without using coffee-script-source.
Changing 'application' to 'default' is a terrible solution though, because it just removes all of the application's css styling. I do not recommend it at all.
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.
# 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
we should only change line 6 from application
to default
in /app/views/layouts/application.html.erb . changing line 5 will result in stylesheets not loading.
You need to read the instruction in the rails page. You need ExecJS gem and some JS runtime.
More practical: 1.- Install some Runtime JS, for example node.js
2.- get ExecJS gem-> gem install execjs
Explication:
From the rails page:
"Compiling CoffeeScript and JavaScript asset compression requires you have a JavaScript runtime available on your system, in the absence of a runtime you will see an execjs error during asset compilation. Usually Mac OS X and Windows come with a JavaScript runtime installed. Rails adds the therubyracer gem to the generated Gemfile in a commented line for new apps and you can uncomment if you need it. therubyrhino is the recommended runtime for JRuby users and is added by default to the Gemfile in apps generated under JRuby. You can investigate all the supported runtimes at ExecJS."
From hte gitHub of ExecJS:
"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
Duktape.rb - Duktape JavaScript interpreter
Node.js
Apple JavaScriptCore - Included with Mac OS X
Microsoft Windows Script Host (JScript)
Google V8
mini_racer - Google V8 embedded within Ruby"
Its problem with turbolinks gem so its creating error
So in app\views\layouts\application.html.erb change this
<%= stylesheet_link_tag 'application.css', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application.js', 'data-turbolinks-track': 'reload' %>
from
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
and uncomment the line no.15 in app\assets\javascripts\application.js
require turbolinks
and copy it into app\assets\stylesheets\application.css at the end of file
From this your css and js will be run
On Windwos 10
Just install node.js and make sure node executable is in path variable.
(On Windows 10 - Rails 4.2.5): I solved by doing this:
1) Install nodes.js
2) Install the coffe-script-source gem
gem 'coffee-script-source', '1.8.0'
3) Add this line in "config\initializers\assets.rb"
Rails.application.config.assets.precompile + =% w (application.css)
For Windows Users You can setup execjs runtime path to Node
config/boot.rb
ENV['EXECJS_RUNTIME'] = 'Node'
참고URL : https://stackoverflow.com/questions/28421547/rails-execjsprogramerror-in-pageshome
'programing tip' 카테고리의 다른 글
Spyder 편집기 배경을 어둡게 변경하는 방법은 무엇입니까? (0) | 2020.11.07 |
---|---|
ASP.NET Development Server 대신 IIS에 디버거를 연결하려면 어떻게합니까? (0) | 2020.11.07 |
Xcode 전체 스택 추적 (0) | 2020.11.06 |
LINQ를 사용하여 문자열을 정수 배열로 변환 (0) | 2020.11.06 |
Python : 들여 쓰기에 4 개의 공백을 사용합니다. (0) | 2020.11.06 |