这似乎是一个重复的问题,但是所有解决方案似乎都不适合我。我的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应用程序。我不明白这是什么问题。我的红宝石版本是2.1.6请帮助。
我正在关注RoR 4。我遇到了相同的错误couldn't find file 'jquery' with type 'application/javascript'
。我做了以下工作,并成功运行了我的应用程序
gem 'jquery-rails'
和gem 'turbolinks'
bundle update
bundle install
这种情况经常发生,因为Gemfile缺少jquery依赖项自行解决所需的gem。
为此,在Rails 5.x中,添加
gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
gem 'rails-ujs', '~> 0.1.0'
此后,运行捆绑软件安装。
重新启动服务器以更新最新的更改,瞧,它起作用了!
这是由于Windows已提供默认的JavaScript运行时,但存在一些兼容性问题。最简单的解决方法是从http://nodejs.org/download/
安装nodejs,然后重新启动PC。这解决了所有问题。
有关此问题的更多详细信息,请参阅此页面:ExecJS::RuntimeError on Windows trying to follow rubytutorial
在您的控制器文件中,您不能通过编写来告诉Rails不要使用布局
layout false
在第二行的控制器类正下方
class ExampleController < ApplicationController
layout false
转到gemfile并确保未注释gem jquery-rails。运行捆绑安装。应该这样做。
您只需要在Gemfile中添加gem'jquery-rails'并运行bundle install。它对我有用。
此问题可以通过以下步骤解决。
请确保application.js中存在require jquery语句
//= require jquery
//= require jquery_ujs
请确保所有必需的宝石都存在于Gemfile中(如果没有)现在添加它并执行bundle install
命令。
gem 'jquery-rails', '~> 4.3', '>= 4.3.3'
gem 'rails-ujs', '~> 0.1.0'3.'
如果仍然显示错误,请通过runnig更新您的节点
sudo npm update npm -g
最后刷新您的应用程序。
您也可以尝试在终端中运行gem install jquery-rails
。它对我有用。