问题
我有一个 Rails 3.0.4 应用程序,我按照Railscast 视频中的说明升级到 3.1.4 :“升级到 rails 3.1” 。
现在我遇到了资产问题,因为它们没有解决,在服务器日志中给出如下消息:
Started GET "/assets/application.css" for 127.0.0.1 at 2012-04-08 03:57:13 -0500
Served asset /application.css - 404 Not Found (15ms)
ActionController::RoutingError (No route matches [GET] "/assets/application.css"):
Rendered /usr/local/rvm/gems/ruby-1.9.2-p318/gems/actionpack-3.1.4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (14.3ms)
Started GET "/assets/application.js" for 127.0.0.1 at 2012-04-08 03:57:13 -0500
Served asset /application.js - 404 Not Found (35ms)
ActionController::RoutingError (No route matches [GET] "/assets/application.js"):
这些文件在assets
目录中:
$ ls app/assets/*/application*
app/assets/javascripts/application.js app/assets/stylesheets/application.css
并包含:
$ cat app/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require_self
//= require_tree .
$ cat app/assets/stylesheets/application.css
/*
*= require_self
*= require_tree .
*/
我想一切都配置好了。这里我放了一些文件块:
Gemfile
, 包含所需的资产宝石:group :assets do gem 'sass-rails', '~> 3.1.3' gem 'coffee-rails', '~> 3.1.0' gem 'uglifier' end
application.rb
, 已启用资产:config.assets.enabled = true config.assets.version = '1.0'
development.rb
:config.assets.compress = false config.assets.debug = true
最后......
application.html.erb
布局:<%= stylesheet_link_tag 'application' %> <%= javascript_include_tag 'application' %>
阶段
我现在在开发环境中。
测试
如果我请求
http://localhost:3000/assets/images/rails.png
,它会抛出No route matches [GET] "/assets/images/rails.png"
,但文件在那里:$ ls app/assets/images/rails.png app/assets/images/rails.png
然后我执行
rake assets:precompile
:$ bundle exec rake assets:precompile /usr/local/rvm/rubies/ruby-1.9.2-p318/bin/ruby /usr/local/rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets /usr/local/rvm/rubies/ruby-1.9.2-p318/bin/ruby /usr/local/rvm/gems/ruby-1.9.2-p318/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
然后,执行服务器(
rails s
)并再次请求图像(rails.png
):$ rails s => Booting WEBrick => Rails 3.1.4 application starting in development on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server /usr/local/rvm/gems/ruby-1.9.2-p318/gems/actionpack-3.1.4/lib/action_dispatch/http/mime_type.rb:101: warning: already initialized constant PDF [2012-04-08 04:53:06] INFO WEBrick 1.3.1 [2012-04-08 04:53:06] INFO ruby 1.9.2 (2012-02-14) [i686-linux] [2012-04-08 04:53:06] INFO WEBrick::HTTPServer#start: pid=16702 port=3000 Started GET "/assets/images/rails.png" for 127.0.0.1 at 2012-04-08 04:53:14 -0500 Served asset /images/rails.png - 404 Not Found (38ms) ActionController::RoutingError (No route matches [GET] "/assets/images/rails.png"): Rendered /usr/local/rvm/gems/ruby-1.9.2-p318/gems/actionpack-3.1.4/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (125.2ms)
那么怎么了?, 难道我做错了什么?