Frequently Asked Questions
Can I use a variable from my controller in my Sass file?
No. Sass files aren’t views. They’re compiled once into static CSS files, then left along until they’re changed and need to be compiled again. Not only don’t you want to be running a full request cycle every time someone requests a stylesheet, but it’s not a great idea to put much logic in there anyway due to how browsers handle them.
If you really need some sort of dynamic CSS, you can define your ownusing Ruby that can access the database or other configuration. Be aware when doing this that Sass files are by default only compiled once and then served statically.
If you really, really need to compile Sass on each request, first make sure you have adequate caching set up. Then you can use
:custom option to pass in data that from your Sass functions.