Question

i'm working on Michael Hartl's ruby on rails tutorial and i've run into a problem that i haven't been able to fix for days.

when trying to load the page, chrome reads:

Sprockets::FileNotFound in StaticPages#home
Showing /Users/azimmer/rails_projects/sample_app/app/views/layouts/application.html.erb where line #7 raised:

couldn't find file 'jquery'
  (in /Users/azimmer/rails_projects/sample_app/app/assets/javascripts/application.js:13)
Extracted source (around line #7):
4
5
6
7
8
9
10

      <title><%= full_title(yield(:title)) %></title>
      <%= stylesheet_link_tag "application", media: "all",
                                             "data-turbolinks-track" => true %>
      <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
      <%= csrf_meta_tags %>
      <%= render 'layouts/shim' %>
      </head>

Rails.root: /Users/azimmer/rails_projects/sample_app

here is my gemfile:

source 'https://rubygems.org'
ruby '2.0.0'
#ruby-gemset=railstutorial_rails_4_0

gem 'rails', '4.0.2'
gem 'bootstrap-sass', '2.3.2.0'
gem 'bcrypt-ruby', '3.1.2'

group :development, :test do
  gem 'sqlite3', '1.3.8'
  gem 'rspec-rails', '2.13.1'
end

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'

gem 'sass-rails', '4.0.2'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '2.3.0'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
gem 'factory_girl_rails', '4.2.1'

end

group :doc do
  gem 'sdoc', '0.3.20', require: false
end

group :production do
  gem 'pg', '0.15.1'
  gem 'rails_12factor', '0.0.2'
end

and here is my application.html.erb file:

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag "application", media: "all",
                                           "data-turbolinks-track" => true %>
    <%= javascript_include_tag "application", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
  <body>
    <%= render 'layouts/header' %>
    <div class="container">
      <%= yield %>
      <%= render 'layouts/footer' %>
      <%= debug(params) if Rails.env.development? %>
    </div>
  </body>
</html>

my application.js file is totally untouched. i have tried everything from adding gem rubyracer, to editing the runtimes.rb file in execjs recommended on another thread. i'm considering just starting over from scratch in order to get everything to work, at least in that case i would relearn a lot of what i've learned, but i'm hoping someone can at least help me figure out what is going on here.

thanks a bunch for your help!

cheers, alex

EDIT

it works if i change the line from

<%= javascript_include_tag 'application', "data-turbolinks-track" => true %>

to

<%= javascript_include_tag :default, "data-turbolinks-track" => true %>

could anyone explain what this means? and how making that change might affect my application in a negative way? thank you for the help!

Was it helpful?

Solution

Add the following lines to the app/assets/javascripts/application.js file

//= require jquery
//= require jquery_ujs

Also make sure that you have run bundle install.

After this run bundle show jquery-rails to verify that gem was successfully installed.

EDIT

Update your Gemfile as below: jquery-rails and few other gems required in all the environments were listed under test group so you couldn't access them in development environment. Correct the Gemfile as below:

gem 'sass-rails', '4.0.2'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '2.3.0'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'

group :test do
  gem 'selenium-webdriver', '2.35.1'
  gem 'capybara', '2.1.0'
  gem 'factory_girl_rails', '4.2.1'
end

After this bundle update and bundle install. You should be good to go.

OTHER TIPS

I had a similar issue, the problem was not related to the existing gems but rather with the cached version of them.

The following steps solved the issue for me:

  1. Specify the actual versions for the affected gems
  2. Clean the asset pipeline by doing rake assets:clean
  3. Clean your browser's cache
  4. Start the server again

This process won't be the same for everyone as the issue here is tied to the cached version of the gems, as I've already mentioned.

At least it should help to find the solution.

If you are using rails 5. you need to install node.js using npm install, so that rails install the frontend requirments automatically for us. This solved my problem.

Add commands /config/initialize/assets

Rails.application.config.assets.paths << Rails.root.join('node_modules')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top