我刚刚完成Mike Hartle rails教程的第五章,当我将文件加载到heroku时,有点困惑,无论出于什么原因,css都没有像我本地那样工作。这是我的heroku日志的副本,如果这有帮助的话。
2013-09-17T00:40:31.225391+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:25:in `tagged'
2013-09-17T00:40:31.225544+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/static.rb:64:in `call'
2013-09-17T00:40:31.225544+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2013-09-17T00:40:31.225544+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2013-09-17T00:40:31.359182+00:00 heroku[router]: at=info method=GET path=/favicon.ico host=fathomless-earth-8911.herokuapp.com fwd="66.235.48.7" dyno=web.1 connect=1ms service=4ms status=304 bytes=0
2013-09-17T00:40:31.225689+00:00 app[web.1]:
2013-09-17T00:40:31.225689+00:00 app[web.1]:
2013-09-17T00:40:31.225689+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/images/rails.png"):
2013-09-17T00:40:31.225689+00:00 app[web.1]:
2013-09-17T00:40:31.225689+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:38:in `call_app'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `block in call'
2013-09-17T00:40:31.225689+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `block in tagged'
2013-09-17T00:40:31.225689+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `tagged'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:25:in `tagged'
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2013-09-17T00:40:31.226188+00:00 app[web.1]:
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:511:in `call'
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2013-09-17T00:40:31.226188+00:00 app[web.1]:
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:97:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.0/lib/action_dispatch/middleware/static.rb:64:in `call'
2013-09-17T00:40:31.226038+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'
2013-09-17T00:40:31.226188+00:00 app[web.1]: vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
答案 0 :(得分:0)
在生产中,资产管道将启动,您的应用将查找资产的预编译版本。我不熟悉该教程,但我假设因为这是css和javascript在生产中无法使用的主要原因(heroku)。有两种方法可以解决这个问题......
第一种方法是通过从应用程序目录运行precompile命令来预编译heroku上的资产:
heroku run bundle exec rake assets:precompile
第二种方式(不建议)是通过在config / environments / production.rb文件中注释掉这些行来关闭资产管道:
# Do not fallback to assets pipeline if a precompiled asset is missed.
# config.assets.compile = false
如果要禁用预编译资产,您可能还想关闭资产网址的摘要
# Generate digests for assets URLs.
# config.assets.digest = true
答案 1 :(得分:0)
我遇到了同样的问题(使用Windows 7)。我发现上面的Heijmans只能部分回答这个问题。 Hartl对于此错误发生的原因或方式并不十分具体,但确实解决了第2.3.5节和第3章介绍结束时的问题。
我的工作经过以下过程。 首先,我跑了
> heroku run bundle exec rake assets:precompile
> heroku open
但我仍然有错误。然后我按照以下方式遵循哈特尔在书中的建议。
> git add .
> git commit -m "Add precompiled assets for Heroku"
> git push
> git push heroku master
> heroku run rake db:migrate
> heroku open
有趣的是,Hartl声称“这不应该是必要的,而且我无法重现这个问题,但报告很常见,我把它包含在这里供参考。”
[tag: heroku]
[tag: railstutorial.org]
[tag: Windows 7]
[tag: Rails 4]