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 own Sass functions using 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 Sass::Engine to render the code, using the :custom option to pass in data that can be accessed from your Sass functions.

You still haven't answered my question!

Sorry! Try looking at the Sass reference, If you can't find an answer there, feel free to ask in #sass on or send an email to the mailing list.