5

到目前为止,这就是我所做的。

  1. 我在 Capfile 中加载了资产:js 仍然无法正常工作 http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

  2. 我将咖啡轨从资产移到主要部分:仍然无法正常工作

    宝石'咖啡轨','〜> 3.2.1'

    group :assets do gem 'sass-rails', '~> 3.2.3' end

更新:生产环境

SolidAdmin::Application.configure do # 此处指定的设置将优先于 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
  Paperclip.options[:command_path] = "/usr/bin/"
  # 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

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

其他一切都几乎是默认的/注释掉了

4

4 回答 4

5

固定的!切换:

config.assets.compile = false

至:

config.assets.compile = true

现在它起作用了。

于 2013-07-21T18:24:06.523 回答
5

编辑:通过聊天交谈后,在页面中包含两次 jquery 是一个问题。

检查您的页面(liquid-radio.com)后,我看到了一个很大的错误:

<!DOCTYPE html>
<html>
<head>
  <title>liquid.radio</title>
  <link href="/assets/application-c9ed21e2be2e7bb9955d6a0d89357d16.css" media="all" rel="stylesheet" type="text/css" />
  <script src="/assets/application-09500810259983928e0b1b4d46b49071.js" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="MYdcXuDSzYg1qSHrRwx0y0VK5VmqhWmLLGiYSOX7pOI=" name="csrf-token" />
</head>
<body style="background: #FFF;">

<!DOCTYPE html>
<html>
    <head>

您将第一部分重复了几次,使您的 html 无效。

于 2013-07-22T13:00:07.903 回答
3

我使用的是 Rails 4.2.6。

为了解决我的错误,我必须运行以下命令;

  1. rake assets:clean- 这是为了清理我的资产
  2. 我必须修复application.js文件中的任何问题。这主要是我导入外部 js 库的顺序。
  3. rake assets:precompile- 这用于预编译资产
  4. config/environments/production.rb,我不得不改变这条线

    config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?

    config.serve_static_files = true

这意味着 rails 应用程序现在可以提供由assets:precompile

完成此操作并重新启动应用程序后,一切都很好!

于 2016-08-20T21:38:57.750 回答
1

我看到的一个问题是您现在将让 Rails 服务器(puma、unicorn 等)为您的静态文件提供服务。在生产服务器上,您会希望您的服务器(例如 Nginx)为这些静态页面提供服务。

如果您的 JS/CSS 正在开发中,那么您只需要 rake assets:precompile在推送到生产环境之前运行即可。然后是配置应用程序服务器以与生产服务器一起工作的问题。

于 2017-02-06T05:30:27.010 回答