1

我的应用程序在开发中运行得很好,但昨天我试图将它移到我的生产服务器上,经过一些权限和路径的工作,我虽然得到了它的工作。但似乎我无法加载 JS 资产,而图像和 css 工作正常。起初我认为是引导 js 文件让我的生活变得悲惨,但删除它只会让我在下一个 JS 资产时出错。

https://dl.dropboxusercontent.com/u/32242733/jsfail.png

生产.rb

  # 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 = true

  # 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 = :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

  config.action_mailer.default_url_options = { :host => 'example.com' }
  # ActionMailer Config
  # Setup for production - deliveries, no errors raised
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings = {
    address: "smtp.gmail.com",
    port: 587,
    domain: "example.com",
    authentication: "plain",
    enable_starttls_auto: true,
    user_name: ENV["GMAIL_USERNAME"],
    password: ENV["GMAIL_PASSWORD"]
  }



  # 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

资产

root@flypatterns:/var/www/flypatterns/current# ls public/assets/
application-35684ef44e5902293fd317c512600f66.css       glyphicons-halflings.png
application-35684ef44e5902293fd317c512600f66.css.gz    glyphicons-halflings-white-6cccd17a7aed91dbc0157d343c68c0d9.png
application-66ba1e6c258ba515e18111b4b93c8c57.js        glyphicons-halflings-white.png
application-66ba1e6c258ba515e18111b4b93c8c57.js.gz     images
application.css                        jquery.min-6c267bfd2b3f36e6edccb2e584934c1c.map
application.css.gz                     jquery.min.map
application.js                         manifest.yml
application.js.gz                      patterns
gallery_images                         users
glyphicons-halflings-2851b489e8c39f8fad44fc10efb99c3e.png
4

4 回答 4

4

在部署以下文件之前,我按照 Heroku hello 的此步骤进行以下更改

------环境.rb-----

::ActiveSupport::Deprecation.silenced = true

------生产.rb-----

config.assets.compile = ['*.js', '*.css']

config.active_support.deprecation = :silence

--------application.rb--------

config.assets.enabled = true
config.assets.initialize_on_precompile = false
于 2013-04-19T08:43:11.147 回答
0

尝试改变

  config.serve_static_assets = false

  config.serve_static_assets = true
于 2013-04-19T07:44:25.917 回答
0

我在将应用推送到 heroku 时遇到了问题。我使用了 twitter-bootstrap,在预编译资产时出现了一些错误。所以我切换到手动编译而不是自动预编译。为此,我做了以下事情:

我在 config/application.rb 中将 initialize_on_precompile 设置为 false,如下所示:

config.assets.initialize_on_precompile = false

然后我通过运行手动完成:

bundle exec rake assets:precompile RAILS_ENV=production

终于成功了……

除非您使用任何预定义的前端框架,否则这可能不是您要寻找的解决方案。

于 2013-04-19T08:44:21.160 回答
0

检查您的 application.js 文件我添加了一些代码来执行添加到一些奇怪的文件的 java 脚本代码。问题是我错过了一些必须被注释掉的代码的“/”:-(愚蠢的我,它花了很长时间

bundle exec rake assets:precompile RAILS_ENV=production

向我展示了要查看的文件和行,然后我以崇高的方式打开了该文件。我希望这有助于我花了 5 天时间才找到这个该死的错误 smh

于 2015-06-21T07:00:49.690 回答