未找到链轮文件异常

发布于 2024-12-18 01:06:48 字数 1611 浏览 0 评论 0 原文

我正在尝试一些 Rails 的示例应用程序。我创建了一些 控制器和页面。但是当我尝试访问其中一个时,我得到了一个 网页上的异常:


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`

我使用以下命令创建了一些控制器:

$ 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

只是想知道问题可能出在哪里以及在哪里查找?我是 通过 URL 访问页面: http://localhost:3000/pages/home

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

宁愿没拥抱 2024-12-25 01:06:49

取消注释

//= require jquery

application.js 文件中的行并重新启动应用程序对我有用。

Un-commenting the line

//= require jquery

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

梨涡 2024-12-25 01:06:49

安装 http://metaskills.net/2011/09/26/less-is-more-using-twitter-bootstrap-in-the-rails-3-1-asset-pipeline/

我做了rake assets:clean asset:precompile,但这没有帮助。有用的是按照 afaf12 的建议重新启动 Rails 应用程序。

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.

走过海棠暮 2024-12-25 01:06:49

对我来说,解决方案是运行yarn install。青年MMV

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

如痴如狂 2024-12-25 01:06:49

您的 jquery-rails gem 很可能已经过时了。当我遇到类似的错误时,更新 gem 解决了问题。

您是否从头开始将其创建为 Rails 3.1 应用程序?或者您是否从某处下载代码(或更新旧的应用程序)?

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)?

落花浅忆 2024-12-25 01:06:49

在rails 6.xx中,可以通过执行来解决问题

bundle exec rails webpacker:install

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

bundle exec rails webpacker:install
§普罗旺斯的薰衣草 2024-12-25 01:06:49

只需向 config/initialize/assets 添加注释,然后重新启动 rails 服务器

Rails.application.config.assets.paths << Rails.root.join('node_modules')

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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文