Rails 5.1.6を使用しています。
railsチュートリアル第8章のログインフォームの作成時にブラウザでページを確認したところ、検証のところでUncaught Error: rails-ujs has already been loaded!
というエラーが出ました。
すでにUncaught Error: rails-ujs はロードされているとのことですが
どこを直せばよいのでしょうか?
application.html.erb
1<!DOCTYPE html> 2<html> 3 <head> 4 <title><%= full_title(yield(:title)) %></title> 5 <%= render 'layouts/rails_default' %> 6 <%= render 'layouts/shim' %> 7 </head> 8 <body> 9 <%= render 'layouts/header' %> 10 <div class="container"> 11 <% flash.each do |message_type, message| %> 12 <%= content_tag(:div, message, class: "alert alert-#{message_type}") %> 13 <%# ブロック変数に代入されているflashメッセージを表示 %> 14 <% end %> 15 <%= yield %> 16 <%= render 'layouts/footer' %> 17 <%= debug(params) if Rails.env.development? %> 18 </div> 19 </body> 20</html>
発生している問題・エラーメッセージ
エラーメッセージ ```rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:624 Uncaught Error: rails-ujs has already been loaded! at Rails.start (rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:624:17) at rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:673:15 at rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:676:8 at rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:677:6 at rails-ujs.self-8944eaf3f9a2615ce7c830a810ed630e296633063af8bb7441d5702fbe3ea597.js?body=1:684:4
試したこと
app/assets/javascripts/application.jsの//= require rails-ujs
を削除すると
エラーは消えましたがjavascriptの処理に支障がでてしまうので解決にはならないのでは?と考えました。
application.js
1// This is a manifest file that'll be compiled into application.js, which will include all the files 2// listed below. 3// 4// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's 5// vendor/assets/javascripts directory can be referenced here using a relative path. 6// 7// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8// compiled file. JavaScript code in this file should be added after the last require_* statement. 9// 10// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 11// about supported directives. 12// 13//= require rails-ujs 14//= require turbolinks 15//= require_tree . 16

回答1件
あなたの回答
tips
プレビュー