如何修复模板错误 "CoffeeScript not defined"
How to fix template error "CoffeeScript not defined"
我正在尝试显示我的项目的视图。但我得到这个错误:
ActionView::Template::Error (ReferenceError: CoffeeScript is not defined):
4: <title>Myapp</title>
5: <%= csrf_meta_tags %>
6:
7: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9: </head>
10:
当我删除第 7-8 行时它可以工作,但我不会有 CSS 或 JavaScript.
大约一周前我没有收到此错误。我不确定是什么原因。我尝试切换 Rails 版本。我试过卸载 Postgres 并重新设置它,但这似乎不是问题所在。
我有 Rails 5.0.0.1 和 "Ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]"。我也在使用 Mac OS Sierra。
我可以将 'application' 更改为 'default' 并且它有效,但我不明白为什么它在大约一周前有效,而不是现在。
我还设置了视图和控制器,这就是为什么当我删除第 7-8 行时它起作用的原因。
这是我的 gem 文件:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# 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.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# 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', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
最近更新的 coffe-script-source gem 1.12.1 有问题。问题是这个版本的源文件是空的。已经有一个 open issue ,应该会尽快修复。
现在您可以将其添加到您的 GemFile
gem 'coffee-script-source', '= 1.11.1'
和运行 bundle update coffee-script-source
直到它被修复。
我还必须使用 gem uninstall coffee-script-source
,然后 gem install coffee-script-source
... 因为我的 gemfile.lock 无论我更新多少次 'bundle install' 或 'bundle update' 删除 gemfile 中的 coffe-script 和 coffee-script-source 条目后。
我正在尝试显示我的项目的视图。但我得到这个错误:
ActionView::Template::Error (ReferenceError: CoffeeScript is not defined):
4: <title>Myapp</title>
5: <%= csrf_meta_tags %>
6:
7: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
8: <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9: </head>
10:
当我删除第 7-8 行时它可以工作,但我不会有 CSS 或 JavaScript.
大约一周前我没有收到此错误。我不确定是什么原因。我尝试切换 Rails 版本。我试过卸载 Postgres 并重新设置它,但这似乎不是问题所在。 我有 Rails 5.0.0.1 和 "Ruby 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin16]"。我也在使用 Mac OS Sierra。
我可以将 'application' 更改为 'default' 并且它有效,但我不明白为什么它在大约一周前有效,而不是现在。
我还设置了视图和控制器,这就是为什么当我删除第 7-8 行时它起作用的原因。
这是我的 gem 文件:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
# Use postgresql as the database for Active Record
gem 'pg', '~> 0.18'
# Use Puma as the app server
gem 'puma', '~> 3.0'
# 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.2'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# 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', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
最近更新的 coffe-script-source gem 1.12.1 有问题。问题是这个版本的源文件是空的。已经有一个 open issue ,应该会尽快修复。
现在您可以将其添加到您的 GemFile
gem 'coffee-script-source', '= 1.11.1'
和运行 bundle update coffee-script-source
直到它被修复。
我还必须使用 gem uninstall coffee-script-source
,然后 gem install coffee-script-source
... 因为我的 gemfile.lock 无论我更新多少次 'bundle install' 或 'bundle update' 删除 gemfile 中的 coffe-script 和 coffee-script-source 条目后。