Erik Nomitch
Erik Nomitch

Reputation: 1665

Prevent Rails 4 Sprocket Asset Pipeline from caching a specific file

I have a file globals.css.scss.erb which only contains:

<%= Styles.output %>

Styles is a custom module to output formatted SCSS/SASS global variables based on a YAML file.

My issue is that when I change the YAML file, globals.css does not get updated (i.e., it's cached by Sprockets).

I want to disable caching on globals.css, not all of my assets. Is this possible? This only has to work for my development environment.

Thanks,

Erik

P.S., There is this post which does not solve the issue.

Upvotes: 1

Views: 371

Answers (1)

intale
intale

Reputation: 831

As I understood, you need always to recompile .erb assets. Here is the solution:

Sprockets::Asset.class_eval do
  alias_method :orig_dependency_fresh?, :dependency_fresh?
  def dependency_fresh?(environment, dep)
    if dep.pathname.extname.eql? '.erb'
      false
    else
      orig_dependency_fresh?(environment, dep)
    end
  end
end

Upvotes: 4

Related Questions