前提・実現したいこと
ruby on rails において、task controller をつくり正常に 「XXX#index」の画面を表示したい。
発生している問題・エラーメッセージ
エラーが表示されて /index にアクセスした時に期待している画面が表示されない。
ExecJS::ProgramError in Tasks#index Showing /app_name/app/views/layouts/application.html.slim where line #8 raised: TypeError: Cannot read property 'version' of undefined Rails.root: /app_name Application Trace | Framework Trace | Full Trace (execjs):19:14 (execjs):1:102 app/views/layouts/application.html.slim:8:in `_app_views_layouts_application_html_slim___3139678354113059132_70258517883120'
該当のソースコード
applicationhtmlslim
1doctype html 2html 3 head 4 title 5 | AppName 6 = csrf_meta_tags 7 = csp_meta_tag 8 = stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' 9 = javascript_include_tag 'application', 'data-turbolinks-track': 'reload' 10 body 11 .app-title.navbar.navbar-expand-md.navbar-light.bg-light 12 .navbar-brand Taskleaf 13 .container 14 = yield 15
route
1Rails.application.routes.draw do 2 root to: 'tasks#index' 3 resources :tasks 4 # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html 5end
Gemfile
1source 'https://rubygems.org' 2git_source(:github) { |repo| "https://github.com/#{repo}.git" } 3 4ruby '2.5.3' 5 6# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 7gem 'rails', '~> 5.2.2' 8# Use mysql as the database for Active Record 9gem 'mysql2', '>= 0.4.4', '< 0.6.0' 10# Use Puma as the app server 11gem 'puma', '~> 3.11' 12# Use SCSS for stylesheets 13gem 'sass-rails', '~> 5.0' 14# Use Uglifier as compressor for JavaScript assets 15gem 'uglifier', '>= 1.3.0' 16# See https://github.com/rails/execjs#readme for more supported runtimes 17# gem 'mini_racer', platforms: :ruby 18 19# Use CoffeeScript for .coffee assets and views 20gem 'coffee-rails', '~> 4.2' 21# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 22gem 'turbolinks', '~> 5' 23# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 24gem 'jbuilder', '~> 2.5' 25# Use Redis adapter to run Action Cable in production 26# gem 'redis', '~> 4.0' 27# Use ActiveModel has_secure_password 28# gem 'bcrypt', '~> 3.1.7' 29 30# Use ActiveStorage variant 31# gem 'mini_magick', '~> 4.8' 32 33# Use Capistrano for deployment 34# gem 'capistrano-rails', group: :development 35 36# Reduces boot times through caching; required in config/boot.rb 37gem 'bootsnap', '>= 1.1.0', require: false 38 39group :development, :test do 40 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 41 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 42end 43 44group :development do 45 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 46 gem 'web-console', '>= 3.3.0' 47 gem 'listen', '>= 3.0.5', '< 3.2' 48 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 49 gem 'spring' 50 gem 'spring-watcher-listen', '~> 2.0.0' 51end 52 53group :test do 54 # Adds support for Capybara system testing and selenium driver 55 gem 'capybara', '>= 2.15' 56 gem 'selenium-webdriver' 57 # Easy installation and use of chromedriver to run system tests with Chrome 58 gem 'chromedriver-helper' 59end 60 61# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 62gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 63 64gem 'slim-rails' 65gem 'html2slim' 66gem 'bootstrap' 67gem 'execjs' 68gem 'therubyracer' 69 70gem 'coffee-script-source', '1.8.0'
試したこと
coffee-script-sourceを追記することで解決するとの記事を見つけ、試しましたが解決しませんでした。
またnodejsのパスが通ってない可能性を考えてnodejs -vを行いましたが、パスは正常に通っていました。
補足情報(FW/ツールのバージョンなど)
rails 5.2.2
ruby 2.5.3
mac Catalina 10.15.7
丁寧すぎるDocker-composeによるrails5 + MySQL on Dockerの環境構築(Docker for Mac)
https://qiita.com/azul915/items/5b7063cbc80192343fc0
上記の記事を参考にしてdocker-composeで環境を構築しました。
javascript_include_tag 'application'としていますが、これで参照されるJavaScriptコードはどのようになっていますでしょうか?
ご返信ありがとうございます。
application.jsとtasks.coffeeは以下のようにコメントのみでした。
```application
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
```
```taskscoffee
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
```
またcable.jsというのもありました。
以下のようになっております
```cablejs
// Action Cable provides the framework to deal with WebSockets in Rails.
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
//
//= require action_cable
//= require_self
//= require_tree ./channels
(function() {
this.App || (this.App = {});
App.cable = ActionCable.createConsumer();
```
回答1件
あなたの回答
tips
プレビュー