user938363
user938363

Reputation: 10360

The right way to load a CSS file in Rails 3.2 in production

In our rails 3.2 app, a jquery-ui.css file was saved under app/assets/stylesheets/ for datepicker theme. In application view, the css file was referred as this:

<link href="jquery-ui.css" rel="stylesheet" type="text/css"/ >

In applicaion.css.scss, did:

@import "jquery-ui.css";

In test environment, the CSS was referred correctly and there is theme with datepicker. However in production environment, there was none. We did assets precompile in production (with sub uri). Is there anything we missed in the setup?

Update

config/environment/production.rb

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

  # 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

Upvotes: 1

Views: 150

Answers (2)

lima_fil
lima_fil

Reputation: 1771

There could be some @import problems, regarding sass version https://github.com/sass/sass/issues/193.

Rename "jquery-ui.css" to "_jquery-ui.scss" and import it as partial @import "jquery-ui";

Use relative path from application.css.scss file @import "relative/path/jquery-ui"

Upvotes: 1

Sean
Sean

Reputation: 427

I highly recommend stashing any 3rd party libraries in your vendor/assets library. For more info on this read through the http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

Move your jquery-ui.css to vendor/assets/stylesheets and try this instead of @import for you vendor manifest

/*
//= jquery-ui
*/

Upvotes: 2

Related Questions