If you've ever stuck a Slim file in the assets folder and attempted to access it via it's base extension you'll know it doesn't work quite like you'd probably expect. If I have a file called '/assets/app/templates/test.html.slim' I can only access it if I go to that exact path in the browser and even then it's still in Slim format. The ideal outcome is to be able to access '/assets/app/templates/test.html' and for the engine to respond with HTML. Here's how we fix that.
- Create a file in the '/config/initializers/' directory called 'slim_assets.rb' (or what ever you want to call the file - it doesn't matter).
- Within that file, paste the following code:
This piece of code will register the '.slim' extension in our asset pipeline. Now, when we see a '.slim' file it will activate the Slim:template engine and all will be good.
- Restart the server and try accessing the file in the browser.
With any luck, you'll now see the HTML counterparts for the Slim templates in your asset pipeline! For completeness sake, I am using Rails 3.2.12 with Slim 1.3.6.