【问题标题】:invalid css on rails app Michael Hartl tutorialRails 应用程序 Michael Hartl 教程上的无效 CSS
【发布时间】:2013-09-17 00:54:58
【问题描述】:

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

【问题讨论】:

    标签: heroku


    【解决方案1】:

    我遇到了同样的问题(使用 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]
    

    【讨论】:

    • 你回答了我的 windows rails 问题!坦克!
    【解决方案2】:

    在生产中,资产管道将启动,您的应用将寻找资产的预编译版本。我不熟悉该教程,但我假设因为这是 css 和 javascript 在生产中不可用的主要原因(heroku)。有两种方法可以解决这个问题......

    第一种方法是通过从应用目录运行预编译命令在 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-20
      • 1970-01-01
      相关资源
      最近更新 更多