2013-09-27 68 views
0

我是Rails的新手,我正在使用Rails 3.2.0開發一個應用程序。所以,當我在我的本地機器工作一切都很好,頁面都設計有望與下列頭:Heroku中的資源不能編譯成一個文件

<head> 
    <title>Ruby on Rails Tutorial Sample App</title> 
    <link href="/assets/application.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
<link href="/assets/custom.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
<link href="/assets/static_pages.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
<link href="/assets/users.css?body=1" media="all" rel="stylesheet" type="text/css" /> 
    <script src="/assets/jquery.js?body=1" type="text/javascript"></script> 
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script> 
<script src="/assets/static_pages.js?body=1" type="text/javascript"></script> 
<script src="/assets/users.js?body=1" type="text/javascript"></script> 
<script src="/assets/application.js?body=1" type="text/javascript"></script> 
    <meta content="authenticity_token" name="csrf-param" /> 
<meta content="XWFSZcrp1zLXPwqKvANdCgQWr4ws6sM2xqylAYVprrQ=" name="csrf-token" /> 
    <!--[if lt IE 9]> 
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
    </head> 

但後來我做了承諾,並將它推到Heroku的:

git push heroku 

但我頁面沒有設計需要; Heroku上的一些頁面的頭部:

<head> 
    <title>Ruby on Rails Tutorial Sample App</title> 
    <link href="/assets/application-7270767b2a9e9fff880aa5de378ca791.css" media="all" rel="stylesheet" type="text/css" /> 
    <script src="/assets/application-3428e82709d7645135002c8fadfafdc6.js" type="text/javascript"></script> 
    <meta content="authenticity_token" name="csrf-param" /> 
<meta content="lSpfx/uG7gZoccxRHqdFBEQArAvQfI/EYXC/G/V79aU=" name="csrf-token" /> 
    <!--[if lt IE 9]> 
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> 
<![endif]--> 
    </head> 

我不知道爲什麼,但「應用程序-.... css」文件是絕對乾淨的!我該如何解決它?我的production.rb:

SampleApp::Application.configure do 
    # Settings specified here will take precedence over those in config/application.rb 

    # Code is not reloaded between requests 
    config.cache_classes = true 

    # Full error reports are disabled and caching is turned on 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 

    # Disable Rails's static asset server (Apache or nginx will already do this) 
    config.serve_static_assets = true 

    # Compress JavaScripts and CSS 
    config.assets.compress = true 

    # Don't fallback to assets pipeline if a precompiled asset is missed 
    config.assets.compile = false 

    # Generate digests for assets URLs 
    config.assets.digest = true 

    # Defaults to Rails.root.join("public/assets") 
    # config.assets.manifest = YOUR_PATH 

    # Specifies the header that your server uses for sending files 
    # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
    config.force_ssl = true 

    # See everything in the log (default is :info) 
    # config.log_level = :debug 

    # Prepend all log lines with the following tags 
    # config.log_tags = [ :subdomain, :uuid ] 

    # Use a different logger for distributed setups 
    # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 

    # Use a different cache store in production 
    # config.cache_store = :mem_cache_store 

    # Enable serving of images, stylesheets, and JavaScripts from an asset server 
    # config.action_controller.asset_host = "http://assets.example.com" 

    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 
    # config.assets.precompile += %w(search.js) 

    # Disable delivery errors, bad email addresses will be ignored 
    # config.action_mailer.raise_delivery_errors = false 

    # Enable threaded mode 
    # config.threadsafe! 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation can not be found) 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners 
    config.active_support.deprecation = :notify 

    # Log the query plan for queries taking more than this (works 
    # with SQLite, MySQL, and PostgreSQL) 
    # config.active_record.auto_explain_threshold_in_seconds = 0.5 
end 

我應該改變什麼?可能在production.rb中的一些設置必須修復?提前致謝。

回答

0

Heroku預先編譯您的application.css文件中的資產。你不應該在頁面的頭部指定各種CSS文件,這看起來就像你在做什麼。你需要確保他們與你application.css文件的文件夾中,並且您application.css文件有以下:

/* 
* This is a manifest file that'll be compiled into application.css, which will include all the files 
* listed below. 
* 
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 
* 
* You're free to add application-wide styles to this file and they'll appear at the top of the 
* compiled file, but it's generally better to create a new file per style scope. 
* 
*= require_self 
*= require_tree . 
*/ 

*= require_tree .線是重要的。它確保它拾取文件夾中的所有css文件並加載它們。

+0

我沒有在佈局中指定樣式表,Rails做到了。我剛把我的CSS文件放到視圖目錄中。我的application.css文件與你的一樣。 – malcoauri

+0

你的CSS文件應該和你的application.css位於同一個目錄中 –

+0

是的,它們在同一個目錄中 – malcoauri