0
このテストでは、レールアプリケーションにjQueryがロードされていないようです:https://stackoverflow.com/a/7341884/6391764。私は私のMacの上でDebianの仮想マシン上で私のRailsアプリケーションを実行しているDoesn't work
jQueryがレールアプリケーションにロードされていません(v 5.1.2)
私が持って出力されます。私はbundle install
とbundle update
の両方を実行した
Gemfile
source 'https://rubygems.org'
gem 'rails' # Well ...
gem 'puma'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :development, :test do
gem 'sqlite3'
gem 'byebug'
end
group :development do
gem 'web-console'
gem 'listen'
gem 'spring'
gem 'spring-watcher-listen'
end
group :test do
gem 'rails-controller-testing'
gem 'minitest-reporters'
gem 'guard'
gem 'guard-minitest'
end
group :production do
gem 'pg'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
:
は、ここに私のです。
マイapplication.js
// 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 turbolinks
//= require_tree .
//= require_self
window.onload = function() {
if (window.jQuery) {
// jQuery is loaded
alert("Yeah!");
} else {
// jQuery is not loaded
alert("Doesn't Work");
}
}
マイapplication.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Title</title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
<%= render 'layouts/header' %>
<%= yield %>
<%= render 'layouts/footer' %>
</body>
</html>