ruby-on-railsassetserbsprockets

Force reload of static assets with embedded Ruby on Rails


I have a js.erb file that uses an environment variable to set a string that will occasionally change. I would like to be able to change the environment variable and immediately be able to load an updated javascript file, but since the source erb file doesn't change, Rails doesn't know it needs to be compiled again. Is there any way I can force it to recompile?

Note: this is in a dev/test environment, not a production environment with precompiled assets.

Note #2: this feature has actually been addressed by sprockets, however the most recent release is older than the PR that adds the feature. I'm looking for a temporary solution that accomplishes the same thing (see https://github.com/rails/sprockets/pull/365)


Solution

  • I was able to accomplish my goal with the answer from this question How to add a rails asset dependency to an environment variable with sprockets?

    However, first I had to upgrade sprockets to >= 3.0.0.