Ruby-on-rails 找不到链轮文件异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8268966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sprockets File not Found Exception
提问by Asker
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:
我正在尝试一些 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`
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
只是想知道问题可能出在哪里以及在哪里查看?我通过 URL 访问页面:http://localhost:3000/pages/home
回答by afaf12
Un-commenting the line
取消注释行
//= require jquery
in application.js file and restarting the application is what worked for me.
在 application.js 文件中并重新启动应用程序对我有用。
回答by jbasko
Had a similar problem with FileNotFoundfor twitter/bootstrapafter installing http://metaskills.net/2011/09/26/less-is-more-using-twitter-bootstrap-in-the-rails-3-1-asset-pipeline/
也有类似的问题,FileNotFound对twitter/bootstrap安装后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.
我做了rake assets:clean assets:precompile,但这没有帮助。按照afaf12的建议重新启动rails应用程序有帮助。
回答by David Sulc
It's quite possible that your jquery-railsgem is outdated. When I ran into a similar error, updating the gem solved the issue.
您的jquery-railsgem很可能已过时。当我遇到类似的错误时,更新 gem 解决了这个问题。
Did you create this as a Rails 3.1 application from scratch? Or are you downloading code from somewhere (or updating an older app)?
您是否从头开始将其创建为 Rails 3.1 应用程序?或者您是从某个地方下载代码(或更新旧应用程序)?

