无法找到类型为'application/javascript'的文件'jquery'

Sou*_*Das 19 jquery assets ruby-on-rails ruby-on-rails-4

这似乎是一个重复的问题,但没有一个解决方案似乎适合我.我有gem jquery-rails我的Gemfile.还有,行

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Run Code Online (Sandbox Code Playgroud)

这是我的Gemfile:

source 'https://rubygems.org'


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'

# 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.1.0'
# 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 following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
#gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Unicorn as the app server
# gem 'unicorn'

# 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'
  # Use mysql as the database for Active Record
  gem 'mysql2'
  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Run Code Online (Sandbox Code Playgroud)

我的application.html.erb:

<!DOCTYPE html>
<html>
<head>
  <title></title>
  <%= stylesheet_link_tag 'application', media: 'all' %>
  <%= javascript_include_tag 'application' %>
  <%= csrf_meta_tags %>
</head>
<body>

<%= yield %>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我无法启动我的Rails应用程序.我不明白这是什么问题.我的ruby版本是2.1.6请帮忙.

nov*_*dev 30

我正在追踪RoR 4.我遇到了同样的错误couldn't find file 'jquery' with type 'application/javascript'.我做了以下操作,并成功运行了我的应用程序

  • gem 'jquery-rails'gem 'turbolinks'
  • bundle update
  • bundle install

  • 但是如果你在一个最近没有更新过的项目中,请小心使用`bundle update`.这将更新你的Gemfile的每个gem,并且让其他东西停止工作是很常见的. (3认同)
  • 要阻止 gem 更新,请在 Gemfile 中提及其版本号。 (2认同)

小智 15

这种情况经常发生,因为Gemfile缺少jquery依赖项自行解决所需的gem.

为此,在Rails 5.x中添加

gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
gem 'rails-ujs', '~> 0.1.0'
Run Code Online (Sandbox Code Playgroud)

在此之后,运行bundle Install.

重新启动服务器以更新最新的更改,瞧,它的工作原理!

  • 宝石“ jquery-rails”足够了 (2认同)

Sou*_*Das 1

这是因为 Windows 中已经提供了默认的 javascript 运行时,但存在一些兼容性问题。最简单的解决方法是安装 Nodejs http://nodejs.org/download/,然后重新启动电脑。这解决了所有问题。

有关该问题的更多详细信息,请参阅此页面:ExecJS::RuntimeError on Windows attempts to follow ruby​​tutorial