ksol
ksol

Reputation: 12235

How to have several output files with rails asset pipeline?

I'm developing a rails app which handles a public area (as of today, static pages), and a private space with authentification, etc. Both of those were developed independently. The first has hand-made style, the latter uses twitter bootstrap.

In production, rails compile my assets into one file, and some styles are conflicting, resulting in the public area having some elements of Twitter Bootstrap... Not what I want.

Is there a way to configure the asset pipeline so when it compiles, there is two output ? the classic application.css, and the front.css?

Upvotes: 4

Views: 382

Answers (1)

Richard Hulse
Richard Hulse

Reputation: 10493

Yes, there is. You need to have two manifest files. I would call the public one application.css and the private one admin.css as this is a common Rails convention.

The application.css should require all the public CSS files, and you will need to remove the require_tree directive as this is what is including things you don't want.

The second manifest file, admin.css, will include the things you want for the private side.

You can then reference these files in the layouts using the Rails helpers.

You will need to add the admin.css (and .js if there is one) to the precompile array for this to work correctly in production:

config.assets.precompile += ['admin.js', 'admin.css']

Upvotes: 7

Related Questions