Triggering a `rails assets:precompile` through a model

Hey guys!

I know you can run rake tasks and system commands in various ways through Rails, but I’m worried about potential side-effects that I might not understand. So I figured I’d ask you guys if you’ve had any experience with this. Here’s more about my use-case:

I have a singleton model, App, with a column color.

I have a variables.scss.erb file with $theme: "<%= App.first.color %>"; which is included in various other scss files.

When I precompile my assets it will take the current value for my App’s color, but if it’s updated in the application it won’t take effect until the next precompile. To me it’d make sense to have a background job triggered when the App’s color column is updated. But this is where I get lost, because I’d want this job to trigger a precompile, but is there anything else it would have to do/should do to work? Is this a bad idea?



Hi Tom,

To me it sounds like you probably want to revisit your deployment pipeline. Even if you have a small site, I think it’s sensible to fully automate the deployment so you can do a new deploy (on a fresh instance) every time you push, even if it’s behind a ‘click to release’ button on your CI. I’m currently using Vultr and have automated the deployment to spin up a new VM with the latest code each push - you don’t need AWS or Azure for this, even many of the cheap VPS providers now have REST APIs which are pretty straight forward.

How often are you changing the app’s colour scheme? To me this sounds like the sort of thing you’d play around with in development, but once you’re live you’re probably not messing with it a great deal…