部署 部署没错误,但是 css,js 等文件不起作用,引用错误!

stephen · 2012年10月29日 · 最后由 lzj_ykds 回复于 2015年06月10日 · 5374 次阅读

用 cap 部署,没错误。访问也正常,就是 css 和 js 文件链接错误。 查看 HTML 源代码,发觉引用地址是这样的:

href="/stylesheets/accounts.css"

按理应该是

assets/front-fa7a06740be9d503478334b52eb662b9.css

应该是设置错误,但是找不出是哪里! 请问应该要怎么解决!

共收到 9 条回复

把你的production.rb发出来看一下。

@zzhattzzh


Gupiao::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 = true

  # Compress JavaScripts and CSS
  config.assets.compress = false

  # 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

  config.assets.js_compressor = :closure
  #config.assets.css_compressor = :scss

  # Defaults to Rails.root.join("public/assets")
  # 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
  config.i18n.default_locale = "zh-CN"

  # 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

# 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

@huacnlee 已经改了,但是还是不行,部署时是否要 cap deploy production?还是 cap deploy staging 也行的的?

@stephen Assets digest 和 cap 是没有关系的


# coding: utf-8
RubyChina::Application.configure do
  # Settings specified here will take precedence over those in config/environment.rb

  # The production environment is meant for finished, "live" apps.
  # 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

  # Specifies the header that your server uses for sending files
  config.action_dispatch.x_sendfile_header = "X-Sendfile"

  # For nginx:
  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

  # If you have no front-end server that supports something like X-Sendfile,
  # just comment this out and Rails will serve the files

  # Use a different logger for distributed setups
  # config.logger = Logger.new("#{Rails.root}/log/#{Rails.env}.log", 'weekly')
  # config.logger.level = Logger::INFO

  # Use a different cache store in production
  # config.cache_store = :mem_cache_store
  config.cache_store = [:dalli_store,"127.0.0.1", {:namespace => "rb-cn", :compression => true}]

  # Disable Rails's static asset server
  # In production, Apache or nginx will already do this
  config.serve_static_assets = true

  # Enable serving of images, stylesheets, and javascripts from an asset server
  config.action_controller.asset_host = Setting.upload_url

  # Disable delivery errors, bad email addresses will be ignored
  # config.action_mailer.raise_delivery_errors = false
  config.action_mailer.default_url_options = { :host => Setting.domain }
  config.action_mailer.delivery_method = :sendmail

  # 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

  # 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

  config.assets.js_compressor  = :uglifier
  config.assets.css_compressor = :scss
  config.assets.precompile += %w(application.css app.js topics.css topics.js window.css front.css cpanel.css search.css
  users.css pages.css pages.js notifications.js notifications.css sites.css sites.js notes.css notes.js 
  gfdynamicfeedcontrol.css gfdynamicfeedcontrol.js mobile.css home.css)


end

@huacnlee 真快,感谢!但是浏览器查看 HTML 源代码,还是没变化

<link href="/stylesheets/front.css" media="screen" rel="stylesheet" type="text/css" />
  <link href="/stylesheets/accounts.css" media="screen" rel="stylesheet" type="text/css" />

还有其他影响这里的设置吗?

8楼 已删除

@ehao 好像没有这个,ruby-china 也没有。我发觉 stylesheet_link_tag 生成的代码就错误了,按理应是生成

/assets/topics-9d788fce7ba54764092b3a011aa754eb.css" 

这样,有一个 assets,但是我生成的就没 assets,直接 stylesheet

@stephen 最后这个问题是怎么解决的,我现在也遇到这个问题,不知错在哪里

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册