0

我刚刚完成了 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'  
4

2 回答 2

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

如果您要禁用预编译资产,您可能还想关闭资产 URL 的摘要

# Generate digests for assets URLs.
# config.assets.digest = true
于 2013-09-20T04:41:22.933 回答
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]
于 2014-05-11T13:00:55.600 回答