I have a Rails (3.1.3 with asset pipeline) application that will be deployed as a war. This application has ui “themes”. Internally, I just have .scss files (Sass) in the assets directory of the Rails application and I let the user switch between them.
I’d like to allow administrators to add themes(basically .scss files) to the application after it has been deployed as a war. How can I allow the functionality without requiring the war be rebuilt/recompiled (using warbler). Ideally, they would be able to add themes without having to do anything with the war file.
I have a similar concern for language files. How can someone dynamically add a language file to a deployed Rails application?
I’m currently pre-compiling assets, namely the themes written using Sass, in production, but I’m open to changing this if it’ll helps solve this issue. Can I precompile asssets outside of the war? Is it possible to set the path of the asset pipeline to outside the war?
Disclaimer: I’m not familiar with WAR at all. My answer may be completely wrong because I have no experience with it. Please understand that I found this to be an interesting challenge and I wanted to find a solution.
I can’t tell if when you create a WAR archive what the application is capable of doing. As a result I decided to use command line to do the actual compiling. However, it shouldn’t be too difficult to include the sass gem and use the compiler directly if needed.
Because I rely on the command line you have to install the sass gem. Then see the README on using the command line interface.
For testing, I created a model called
Themewith the following columns. You may need to change the code below to match the model you have in place.(string) title # the title of the theme(string) stylesheet_file_name # the name of the file that is savedInside of my form I used a different field name to prevent overlapping.
Then inside of my controller I added the code to compile the uploaded scss file and move it into the public directory.
Once you have the css file in place you can include it in your
layout/application.html.erbfile with the following.