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

时间:2015-06-28 16:49:27

标签: jquery ruby-on-rails ruby-on-rails-4 assets

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

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

这是我的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]

我的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>

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

8 个答案:

答案 0 :(得分:28)

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

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

答案 1 :(得分:12)

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

为此,在Rails 5.x中,添加

gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
gem 'rails-ujs', '~> 0.1.0'

在此之后,运行bundle Install。

重新启动服务器以更新最新的更改,瞧,它有效!

答案 2 :(得分:1)

这是因为Windows中已有的默认javascript运行时但存在一些兼容性问题。最简单的解决方法是从Bytestring安装nodejs,然后重新启动PC。这解决了所有问题。

有关该问题的详细信息,请参阅此页:ExecJS::RuntimeError on Windows trying to follow rubytutorial

答案 3 :(得分:0)

在您的控制器文件中,您无法通过编写

告诉rails不使用布局
layout false

直接在第二行的控制器类下

class ExampleController < ApplicationController
layout false

答案 4 :(得分:0)

转到gemfile并确保取消注释gem jquery-rails 。运行捆绑安装。应该这样做。

答案 5 :(得分:0)

您只需在Gemfile中添加gem'jquery-rails'并运行bundle install。它对我有用。

答案 6 :(得分:0)

可以通过以下步骤解决此问题。

  1. 确保application.js中存在require jquery语句

    //= require jquery

    //= require jquery_ujs

  2. 确保所有必需的宝石都存在于Gemfile中(如果没有) 现在添加它并执行bundle install命令。

    gem 'jquery-rails', '~> 4.3', '>= 4.3.3'

    gem 'rails-ujs', '~> 0.1.0'3.'

  3. 如果仍然显示错误,请通过runnig更新您的节点

    sudo npm update npm -g

最后刷新您的应用程序。

答案 7 :(得分:0)

您还可以尝试在终端中运行gem install jquery-rails。 它对我有用。

相关问题