実現したいこと
某参考書にてRuby on Railsを勉強しております。
ブラウザにてページを読み込むとアラートが表示されるとのことなのですが、下記のようなエラーが出てしまい実行されません。
参考書やインターネットにて調べたのですが、解決方法が見つからなかったため質問いたしました。
もし可能でしたら修正点などご教示いただけますと幸いです。
発生したエラー
#####ブラウザ
Showing /Users/(ユーザー名)/Desktop/Ruby on rails Learning/sample/app/views/users/index.html.erb where line #2 raised: The asset "users.js" is not present in the asset pipeline. Extracted source (around line #2): 1 <%= stylesheet_link_tag 'users' %> 2 <%= javascript_include_tag 'users' %> 3 4 <div class='users-index'><%= @hello %></div>
#####ターミナル
ActionView::Template::Error (The asset "users.js" is not present in the asset pipeline. ): 1: <%= stylesheet_link_tag 'users' %> 2: <%= javascript_include_tag 'users' %> 3: 4: <div class='users-index'><%= @hello %></div> app/views/users/index.html.erb:2 app/controllers/users_controller.rb:5:in `index'
該当のソースコード
app/views/users/index.html.erb
Ruby
1<%= stylesheet_link_tag 'users' %> 2<%= javascript_include_tag 'users' %> 3 4<div class='users-index'><%= @hello %></div>
app/assets/stylesheets/users.scss
Ruby
1// Place all the styles related to the users controller here. 2// They will automatically be included in application.css. 3// You can use Sass (SCSS) here: https://sass-lang.com/ 4.users-index { 5 font-weight: bold; 6}
app/assets/javascript/users.coffee
Ruby
1# Place all the behaviors and hooks related to the matching controller here. 2# All this logic will automatically be available in application.js. 3# You can use CoffeeScript in this file: http://coffeescript.org/ 4alert('Hello, world!')
config/initializers/assets.rb
Ruby
1# Be sure to restart your server when you modify this file. 2 3# Version of your assets, change this if you want to expire all your assets. 4Rails.application.config.assets.version = '1.0' 5 6# Add additional assets to the asset load path. 7# Rails.application.config.assets.paths << Emoji.images_path 8# Add Yarn node_modules folder to the asset load path. 9Rails.application.config.assets.paths << Rails.root.join('node_modules') 10 11# Precompile additional assets. 12# application.js, application.css, and all non-JS/CSS in the app/assets 13# folder are already added. 14Rails.application.config.assets.precompile += %w( users.js users.css )
試したこと
下記の質問者様同様、アプリを新規作成した際「user.coffee」ファイルが見当たらなかったため、自作しました。
https://teratail.com/questions/247345
補足情報(FW/ツールのバージョンなど)
- macOS Big Sur ver 11.6
- ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]
- Rails ver 6.1.4.1
- VSCode ver 1.60.2
追記情報
直後にPumaサーバの停止を行い「rails s」コマンドにて再起動を行った際に下記エラーが発生してしまいました。
LoadError (cannot load such file -- coffee_script): bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' bootsnap (1.9.1) lib/bootsnap/load_path_cache/loaded_features_index.rb:89:in `register' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:44:in `require' zeitwerk (2.4.2) lib/zeitwerk/kernel.rb:34:in `require' sprockets (4.0.2) lib/sprockets/autoload/coffee_script.rb:2:in `<main>' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi' bootsnap (1.9.1) lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi' bootsnap (1.9.1) lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require' zeitwerk (2.4.2) lib/zeitwerk/kernel.rb:34:in `require' sprockets (4.0.2) lib/sprockets/coffee_script_processor.rb:17:in `cache_key' sprockets (4.0.2) lib/sprockets/coffee_script_processor.rb:23:in `call' sprockets (4.0.2) lib/sprockets/processor_utils.rb:84:in `call_processor' sprockets (4.0.2) lib/sprockets/processor_utils.rb:66:in `block in call_processors' sprockets (4.0.2) lib/sprockets/processor_utils.rb:65:in `reverse_each' sprockets (4.0.2) lib/sprockets/processor_utils.rb:65:in `call_processors' sprockets (4.0.2) lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>' sprockets (4.0.2) lib/sprockets/processor_utils.rb:33:in `call' sprockets (4.0.2) lib/sprockets/processor_utils.rb:84:in `call_processor' sprockets (4.0.2) lib/sprockets/processor_utils.rb:66:in `block in call_processors' sprockets (4.0.2) lib/sprockets/processor_utils.rb:65:in `reverse_each' sprockets (4.0.2) lib/sprockets/processor_utils.rb:65:in `call_processors' sprockets (4.0.2) lib/sprockets/loader.rb:182:in `load_from_unloaded' sprockets (4.0.2) lib/sprockets/loader.rb:59:in `block in load' sprockets (4.0.2) lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache' sprockets (4.0.2) lib/sprockets/loader.rb:43:in `load' sprockets (4.0.2) lib/sprockets/cached_environment.rb:44:in `load' sprockets (4.0.2) lib/sprockets/bundle.rb:27:in `call' sprockets (4.0.2) lib/sprockets/processor_utils.rb:84:in `call_processor' sprockets (4.0.2) lib/sprockets/processor_utils.rb:66:in `block in call_processors' sprockets (4.0.2) lib/sprockets/processor_utils.rb:65:in `reverse_each' sprockets (4.0.2) lib/sprockets/processor_utils.rb:65:in `call_processors' sprockets (4.0.2) lib/sprockets/loader.rb:182:in `load_from_unloaded' sprockets (4.0.2) lib/sprockets/loader.rb:59:in `block in load' sprockets (4.0.2) lib/sprockets/loader.rb:337:in `fetch_asset_from_dependency_cache' sprockets (4.0.2) lib/sprockets/loader.rb:43:in `load' sprockets (4.0.2) lib/sprockets/cached_environment.rb:44:in `load' sprockets (4.0.2) lib/sprockets/base.rb:81:in `find_asset' sprockets (4.0.2) lib/sprockets/base.rb:88:in `find_all_linked_assets' sprockets (4.0.2) lib/sprockets/manifest.rb:125:in `block (2 levels) in find' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `block in synchronize' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:47:in `synchronize' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:19:in `execute' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:363:in `run_task' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:352:in `block (3 levels) in create_worker' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `loop' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:335:in `block (2 levels) in create_worker' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `catch' concurrent-ruby (1.1.9) lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:334:in `block in create_worker'
調べたところ、起動エラーとのことなのですが、下記を実施した際も変わらずでした。
どなたかお分かりでしたらご教示いただけますと幸いです。
bin/rake tmp:cache:clear
bundle update coffee-script-source
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。