2017-12-21 20 views
0

최근 Heroku에서 호스팅되는 레일 앱을 만들었습니다. 앱에 액세스하면 CSS와 자바 스크립트가 모두로드되지 않습니다. 레일스가 생산 경로의 자산 경로를 미리 표시합니다.

<link rel="stylesheet" media="all" href="/events/assets/application-9a60e8cdcf689d8333e107c58a2d6fe35cd8367ea14a2911c56898e476dadd09.css" data-turbolinks-track="reload" /> 

을 생성하지만 /events/ 부분이 추가해서는 안이다되고있는 URL입니다. 어떤 도움에 감사드립니다

Rails.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 

    # Eager load code on boot. This eager loads most of Rails and 
    # your application in memory, allowing both threaded web servers 
    # and those relying on copy on write to perform better. 
    # Rake tasks automatically ignore this option for performance. 
    config.eager_load = true 

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

    # Attempt to read encrypted secrets from `config/secrets.yml.enc`. 
    # Requires an encryption key in `ENV["RAILS_MASTER_KEY"]` or 
    # `config/secrets.yml.key`. 
    config.read_encrypted_secrets = true 

    # Disable serving static files from the `/public` folder by default since 
    # Apache or NGINX already handles this. 
    # config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 

    # Compress JavaScripts and CSS. 
    config.assets.js_compressor = :uglifier 
    # config.assets.css_compressor = :sass 

    # Do not fallback to assets pipeline if a precompiled asset is missed. 
    config.assets.compile = false 
    config.public_file_server.enabled = true 

    # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 

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

    # 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 

    # Mount Action Cable outside main process or domain 
    # config.action_cable.mount_path = nil 
    # config.action_cable.url = 'wss://example.com/cable' 
    # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ] 

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

    # Use the lowest log level to ensure availability of diagnostic information 
    # when problems arise. 
    config.log_level = :debug 

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

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

    # Use a real queuing backend for Active Job (and separate queues per environment) 
    # config.active_job.queue_adapter  = :resque 
    # config.active_job.queue_name_prefix = "bmasb_#{Rails.env}" 
    config.action_mailer.perform_caching = false 

    # Ignore bad email addresses and do not raise email delivery errors. 
    # Set this to true and configure the email server for immediate delivery to raise delivery errors. 
    # config.action_mailer.raise_delivery_errors = false 

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

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

    # Use default logging formatter so that PID and timestamp are not suppressed. 
    config.log_formatter = ::Logger::Formatter.new 

    # Use a different logger for distributed setups. 
    # require 'syslog/logger' 
    # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') 
    config.relative_url_root = "/events" 

    # Disable serving static files from the `/public` folder by default since 
    # Apache or NGINX already handles this. 
    config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? 

    if ENV["RAILS_LOG_TO_STDOUT"].present? 
    logger   = ActiveSupport::Logger.new(STDOUT) 
    logger.formatter = config.log_formatter 
    config.logger = ActiveSupport::TaggedLogging.new(logger) 
    end 

    # Do not dump schema after migrations. 
    config.active_record.dump_schema_after_migration = false 
end 

:

내 CSS와 JS이 내 환경/production.rb 파일입니다 views/layouts/application.html.haml

에서 호출되고 있습니다!

+0

캐시를 지운 다음에 자산을 다시 사전 컴파일하십시오. –

답변

1

이 줄 config.relative_url_root = "/events"은 URL로 /events을 앞에 추가된다. 이것이 의도적인데 앱이 이벤트 하위 디렉토리에있는 경우 다른 문제가 원인 일 수 있습니다. RAILS_ENV=production rake assets:precompile 또는 RAILS_RELATIVE_URL_ROOT=/events RAILS_ENV=production rake assets:precompile을 로컬로 실행하면 오류에 대한 추가 정보를 얻을 수 있습니다.

0

heroku에 업로드하는 동안 자산을 ​​사전 컴파일 했습니까? 당신의 production.rb에서

RAILS_ENV=production rake assets:precompile 
+0

애셋이 서버에 있지만 앱이 애셋을 잘못 라우팅하고 있습니다. – fmonper1