17

I was trying out some sample applications for Rails. I created some controllers and pages. But when i try to access one of them i get an exception on the webpage:


Sprockets::FileNotFound in Pages#home
Showing c:/railscode/test_app/app/views/layouts/application.html.erb
where line #6 raised:

couldn't find file 'jquery'
  (in c:/railscode/test_app/app/assets/javascripts/application.js:7)
Extracted source (around line #6):

    3: <head> 
    4:   <title>TestApp</title> 
    5:   <%= stylesheet_link_tag    "application" %> 
    6:   <%= javascript_include_tag "application" %> 
    7:   <%= csrf_meta_tags %> 8: </head> 9: <body>

Rails.root:`c:/railscode/test_app`

I created some controllers using the command:

$ rails generate controller Pages home contact

  create  app/controllers/pages_controller.rb
   route  get "pages/contact"
   route  get "pages/home"
  invoke  erb
  create    app/views/pages
  create    app/views/pages/home.html.erb
  create    app/views/pages/contact.html.erb
  invoke  rspec
  create    spec/controllers/pages_controller_spec.rb
  create    spec/views/pages
  create    spec/views/pages/home.html.erb_spec.rb
  create    spec/views/pages/contact.html.erb_spec.rb
  invoke  helper
  create    app/helpers/pages_helper.rb
  invoke  rspec
  create     spec/helpers/pages_helper_spec.rb
  invoke  assets
  invoke    js
  create      app/assets/javascripts/pages.js
  invoke    css
  create      app/assets/stylesheets/pages.css

Just wanted to know where the problem could be and where to look? I am accessing the page by the URL: http://localhost:3000/pages/home

Deepak Mahakale
  • 22,834
  • 10
  • 68
  • 88
Asker
  • 725
  • 1
  • 4
  • 14

6 Answers6

18

Un-commenting the line

//= require jquery

in application.js file and restarting the application is what worked for me.

afaf12
  • 5,163
  • 9
  • 35
  • 58
11

Had a similar problem with FileNotFound for twitter/bootstrap after installing http://metaskills.net/2011/09/26/less-is-more-using-twitter-bootstrap-in-the-rails-3-1-asset-pipeline/

I did rake assets:clean assets:precompile, but that didn't help. What helped was restarting the rails application as suggested by afaf12.

RAJ
  • 9,697
  • 1
  • 33
  • 63
jbasko
  • 7,028
  • 1
  • 38
  • 51
1

For me, the solution was to run yarn install. YMMV

David Hempy
  • 5,373
  • 2
  • 40
  • 68
0

In rails 6.x.x the problem can be solved by executing

bundle exec rails webpacker:install
Ri1a
  • 737
  • 9
  • 26
0

Just add a comment to your config/initialize/assets and then restart your rails server.

Rails.application.config.assets.paths << Rails.root.join('node_modules')
Dharmik Patel
  • 1,041
  • 6
  • 12
Brain
  • 1
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 31 '22 at 05:49
0

It's quite possible that your jquery-rails gem is outdated. When I ran into a similar error, updating the gem solved the issue.

Did you create this as a Rails 3.1 application from scratch? Or are you downloading code from somewhere (or updating an older app)?

aceofbassgreg
  • 3,837
  • 2
  • 32
  • 42
David Sulc
  • 25,946
  • 3
  • 52
  • 54