我的应用程序在开发中很花哨,但昨天我尝试将它移动到我的生产服务器上,经过一些权限和路径的工作之后,我得到了它的工作。 但似乎我无法加载JS资产,而图像和CSS工作正常。 起初我以为是bootstrap js文件让我的生活变得错了,但删除它只会让我在下一个JS资产上出错。
https://dl.dropboxusercontent.com/u/32242733/jsfail.png
Production.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
答案 0 :(得分:4)
我为Heroku执行此步骤 你好在部署文件
之前做了以下更改------ ----- enviorment.rb
::ActiveSupport::Deprecation.silenced = true
------ ------- Production.rb
config.assets.compile = ['*.js', '*.css']
config.active_support.deprecation = :silence
------- ------- application.rb中
config.assets.enabled = true
config.assets.initialize_on_precompile = false
答案 1 :(得分:0)
尝试更改
config.serve_static_assets = false
到
config.serve_static_assets = true
答案 2 :(得分: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
最后它起作用了......
除非您使用任何预定义的前端框架,否则这可能不是您要寻找的解决方案。
答案 3 :(得分:0)
检查你的application.js文件我添加了一些代码来做一个java脚本代码,添加到一些funk奇怪的文件。问题是我错过了一些必须被注释掉的代码的“/”:(愚蠢的我花了很长时间
bundle exec rake assets:precompile RAILS_ENV=production
向我展示了要查看的文件和行,我在sublime中打开了该文件。我希望这有点花了我5天才能找到这个该死的错误smh