2011-11-02 61 views
1

在使用webrick以生產模式(即rails s -e production)運行的本地機器上,我生成了使用RAILS_ENV=production bundle exec rake assets:precompile的css,其創建了application-d2bcfd35ef1c0c30b7a7ca94e52c0cbd.css,其佈局文件也參考。在開發機器上設置生產服務器以使用rails 3資產管道

加載頁面然而,當我得到的錯誤:

Started GET "/assets/application-d2bcfd35ef1c0c30b7a7ca94e52c0cbd.css" for 127.0.0.1 at 2011-11-02 10:12:55 +0000 

AbstractController::ActionNotFound (The action 'application-d2bcfd35ef1c0c30b7a7ca94e52c0cbd' could not be found for AssetsController): 
    actionpack (3.1.1) lib/abstract_controller/base.rb:116:in `process' 
    actionpack (3.1.1) lib/abstract_controller/rendering.rb:45:in `process' 
    actionpack (3.1.1) lib/action_controller/metal.rb:193:in `dispatch' 
    actionpack (3.1.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch' 
    actionpack (3.1.1) lib/action_controller/metal.rb:236:in `block in action' 
    actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:65:in `call' 
    actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:65:in `dispatch' 
    actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:29:in `call' 
    rack-mount (0.8.3) lib/rack/mount/route_set.rb:152:in `block in call' 
    rack-mount (0.8.3) lib/rack/mount/code_generation.rb:96:in `block in recognize' 
    rack-mount (0.8.3) lib/rack/mount/code_generation.rb:68:in `optimized_each' 
    rack-mount (0.8.3) lib/rack/mount/code_generation.rb:95:in `recognize' 
    rack-mount (0.8.3) lib/rack/mount/route_set.rb:141:in `call' 
    actionpack (3.1.1) lib/action_dispatch/routing/route_set.rb:532:in `call' 
    newrelic_rpm (3.2.0) lib/new_relic/rack/browser_monitoring.rb:18:in `call' 
    airbrake (3.0.4) lib/airbrake/rack.rb:27:in `call' 
    sass (3.1.10) lib/sass/plugin/rack.rb:54:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call' 
    rack (1.3.5) lib/rack/etag.rb:23:in `call' 
    rack (1.3.5) lib/rack/conditionalget.rb:25:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/head.rb:14:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/flash.rb:243:in `call' 
    rack (1.3.5) lib/rack/session/abstract/id.rb:195:in `context' 
    rack (1.3.5) lib/rack/session/abstract/id.rb:190:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/cookies.rb:331:in `call' 
    activerecord (3.1.1) lib/active_record/query_cache.rb:62:in `call' 
    activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
    activesupport (3.1.1) lib/active_support/callbacks.rb:392:in `_run_call_callbacks' 
    activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks' 
    actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:28:in `call' 
    rack (1.3.5) lib/rack/sendfile.rb:101:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call' 
    actionpack (3.1.1) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call' 
    railties (3.1.1) lib/rails/rack/logger.rb:13:in `call' 
    rack (1.3.5) lib/rack/methodoverride.rb:24:in `call' 
    rack (1.3.5) lib/rack/runtime.rb:17:in `call' 
    activesupport (3.1.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call' 
    rack (1.3.5) lib/rack/lock.rb:15:in `call' 
    rack-cache (1.1) lib/rack/cache/context.rb:132:in `forward' 
    rack-cache (1.1) lib/rack/cache/context.rb:241:in `fetch' 
    rack-cache (1.1) lib/rack/cache/context.rb:181:in `lookup' 
    rack-cache (1.1) lib/rack/cache/context.rb:65:in `call!' 
    rack-cache (1.1) lib/rack/cache/context.rb:50:in `call' 
    airbrake (3.0.4) lib/airbrake/user_informer.rb:12:in `call' 
    railties (3.1.1) lib/rails/engine.rb:456:in `call' 
    railties (3.1.1) lib/rails/rack/content_length.rb:16:in `call' 
    railties (3.1.1) lib/rails/rack/log_tailer.rb:14:in `call' 
    rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service' 
    /Users/ttt/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service' 
    /Users/ttt/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' 
    /Users/ttt/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread' 

我在配置軌引導閱讀:

  • config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.

因此改變config.serve_static_assetstrueproduction.rb引用文件正確。有沒有配置webrick來提供資產管道文件的方法?或者是否有任何其他的Rails服務器可以很容易地設置爲我的開發機器在生產模式下運行?

我使用Apache Web服務器在Mac OS 10.6(Snow Leopard)上運行。

+0

爲什麼要在開發環境中預編譯資產? –

+0

當您在本地以開發模式運行時,本地運行在生產模式下還是在服務器上以生產模式運行時,您是否可以更具體地確定發生錯誤的時間:您可以添加(對於問題)關於哪個計算機(Linux,Windows,...)在哪個上下文(Apache,Nginx,...)中想要在生產模式下運行應用程序的信息? – mliebelt

+0

@MarekTihkan - 我想在我的本地機器上預編譯我的資產,這樣我就可以建立一個生產環境而不必實際部署到生產環境 – zlog

回答

1

您可以克隆您的生產環境VagrantRailsCasts episode),這將使開發計算機上的生產環境測試更真實。

您可以創建用於測試生產設置新的環境和標記config.serve_static_assetstrue

你可以嘗試使用其他服務器一樣thin ...

可能是第一個會給你最精確的結果會是如何生產工作,你就不會在使用的WEBrick不瘦生產。

相關問題