2013-05-06 29 views
0

我在本地預編譯資產並將它們推送到S3。在生產中,我得到這個錯誤:Rails忽略S3中的預編譯資產,「找不到文件」bootstrap'「

heroku[router]: at=info method=GET path=/ host=www.someapp.org fwd="76.87.106.226" dyno=web.1 connect=2ms service=614ms status=500 bytes=0 
app[web.1]: ActionView::Template::Error (couldn't find file 'bootstrap' 
app[web.1]: app/views/application/_stylesheets.html.erb:1:in `...' 
app[web.1]: app/views/layouts/application.html.erb:5:in `...' 
app[web.1]: 
app[web.1]: (in /app/app/assets/stylesheets/application.css:11)): 
app[web.1]:  1: <%= stylesheet_link_tag "application", media: "all" %> 

當我在本地生產模式下運行時,我沒有得到該錯誤。

這裏是我的application.rb

require File.expand_path("../boot", __FILE__) 

# Pick the frameworks you want: 
require "active_record/railtie" 
require "action_controller/railtie" 
require "action_mailer/railtie" 
require "active_resource/railtie" 
require "sprockets/railtie" 
# require "rails/test_unit/railtie" 

if defined?(Bundler) 
    # If you precompile assets before deploying to production, use this line 
    Bundler.require(*Rails.groups(:assets => %w(development test))) 
    # If you want your assets lazily compiled in production, use this line 
    # Bundler.require(:default, :assets, Rails.env) 
end 

module SomeApp 
    class Application < Rails::Application 
    require "ksp" 
    require "markdowner" 
    require "patches/carrier_wave" 
    VERSION = "1.0.0" 
    # Settings in config/environments/* take precedence over those specified here. 
    # Application configuration should go into files in config/initializers 
    # -- all .rb files in that directory are automatically loaded. 

    # Custom directories with classes and modules you want to be autoloadable. 
    # config.autoload_paths += %W(#{config.root}/extras) 

    # Only load the plugins named here, in the order given (default is alphabetical). 
    # :all can be used as a placeholder for all plugins not explicitly named. 
    # config.plugins = [ :exception_notification, :ssl_requirement, :all ] 

    # Activate observers that should always be running. 
    # config.active_record.observers = :cacher, :garbage_collector, :forum_observer 

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 
    # config.time_zone = "Central Time (US & Canada)" 

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 
    # config.i18n.load_path += Dir[Rails.root.join("my", "locales", "*.{rb,yml}").to_s] 
    # config.i18n.default_locale = :de 

    # Configure the default encoding used in templates for Ruby 1.9. 
    config.encoding = "utf-8" 

    # Configure sensitive parameters which will be filtered from the log file. 
    config.filter_parameters += [:password] 

    # Enable escaping HTML in JSON. 
    config.active_support.escape_html_entities_in_json = true 

    # Use SQL instead of Active Record"s schema dumper when creating the database. 
    # This is necessary if your schema can"t be completely dumped by the schema dumper, 
    # like if you have constraints or database-specific column types 
    # config.active_record.schema_format = :sql 

    # Enforce whitelist mode for mass assignment. 
    # This will create an empty whitelist of attributes available for mass-assignment for all models 
    # in your app. As such, your models will need to explicitly whitelist or blacklist accessible 
    # parameters by using an attr_accessible or attr_protected declaration. 
    config.active_record.whitelist_attributes = true 

    # Enable the asset pipeline 
    config.assets.enabled = true 

    # Version of your assets, change this if you want to expire all your assets 
    config.assets.version = "1.0" 

    config.generators do |generator| 
     generator.test_framework :rspec, view_specs: false 
    end 

    config.assets.prefix = "/assets/#{Rails.env}" 

    config.filepicker_rails.api_key = ENV["FILEPICKER_API_KEY"] 

    # Allow for CORS requests 
    config.middleware.use Rack::Cors do 
     allow do 
     origins "*" 
     resource "*", headers: :any, methods: [:get, :post, :options] 
     end 
    end 
    end 
end 

這裏是我的production.rb

SomeApp::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 = false 

    # 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 nil and saved in location specified by config.assets.prefix 
    # 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 = :dalli_store 

    # Enable serving of images, stylesheets, and JavaScripts from an asset server 
    config.action_controller.asset_host = "d20eprk8nbwd96.cloudfront.net" 

    # 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 
    config.action_mailer.default_url_options = { host: "www.someapp.org" } 

    # 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 

這裏是我的asset_sync.rb

if defined?(AssetSync) && !(ENV["HOME"] == "/app") 
    AssetSync.configure do |config| 
    config.fog_provider = "AWS" 
    config.fog_directory = ENV["AMAZON_BUCKET"] 
    config.aws_access_key_id = ENV["AMAZON_S3_KEY"] 
    config.aws_secret_access_key = ENV["AMAZON_S3_SECRET"] 

    # Increase upload performance by configuring your region 
    config.fog_region = "us-west-2" 
    # 
    # Don't delete files from the store 
    config.existing_remote_files = ENV["ASSET_SYNC_EXISTING_REMOTE_FILES"] 
    # 
    # Automatically replace files with their equivalent gzip compressed version 
    config.gzip_compression = ENV["ASSET_SYNC_GZIP_COMPRESSION"] 
    # 
    # Use the Rails generated 'manifest.yml' file to produce the list of files to 
    # upload instead of searching the assets directory. 
    config.manifest = ENV["ASSET_SYNC_MANIFEST"] 
    # 
    # Fail silently. Useful for environments such as Heroku 
    # config.fail_silently = true 
    end 
end 

這裏是我的application.css

/* 
*= require bootstrap 
*= require bootstrap-responsive 
*= require font-awesome 
*= require chosen 
*= require bootstrap/tour 
*= require bootstrap/lightbox 
*= require_self 
*/ 

在本地生產模式下,該方法爲我提供了正確的雲端URL。

這裏怎麼回事?

+0

它發生這對我和我解決了移動'bootstrap'寶石了'assets'組。這不是一個新問題,你可以看看這裏:http://stackoverflow.com/q/9213599/1004046或在這裏:http://stackoverflow.com/q/13377374/1004046 – Pigueiras 2013-05-06 21:26:01

+0

我不應該不得不做這個,因爲我是預編譯? – krainboltgreene 2013-05-06 23:19:57

回答

0

儘管在本地進行預編譯,但Heroku仍然試圖在Heroku上進行預編譯。

它會失敗,然後嘗試直接編譯資產。然後這將以描述的方式失敗。

我解決了這個通過創建一個空文件/public/assets/manifest.yml,即使我的配置說資產是/public/assets/production/