Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3: assets pipeline + many layouts

I have a huge project with rails 3.1 (without assets pipeline). This project has a lot of different layouts, for example:

  • application
  • home
  • console

And etc. Each layout has a huge list of js and css (to attach them we use javascript_include_tag and stylesheet_link_tag). Is it possible to enable assets pipeline so it will include different js/css files for different layouts and it will generate different application.js and application.css for each layout in production?

like image 306
ExiRe Avatar asked May 08 '13 10:05

ExiRe


1 Answers

yes it is

application.css

*= require this_file
*= require that_file

home.css

*= require this_file
*= require home_file

etc etc

you can then do this in your application layout:

 <%= stylesheet_link_tag "application", media: "all" %>

and the home layout

 <%= stylesheet_link_tag "home", media: "all" %>

you will also need to tweak production.rb

  config.assets.precompile += %w( application.css home.css home.js )

including all the compiled files you reference in the layouts.

like image 95
Dom Barker Avatar answered Sep 17 '22 20:09

Dom Barker