Skip to content

Cannot inject behavior into assets.context_class when precompiling assets. #307

Closed
@bhaibel

Description

@bhaibel

I'm mixing Rails helpers into my sprockets context per the documentation here:

https://github.com/rails/sprockets/blob/master/lib/sprockets/context.rb#L6-L18

This is happening in a Rails.application.config.after_initialize block. So something like this

Rails.application.config.after_initialize do
  Rails.application.assets.context_class.class_eval do
    include RailsViewHelperStuff
  end
end

When I precompile assets in the development rails env, this works fine. However, once I start working in an env where Rails.application.config.assets.compile is false, I get a NoMethodError: undefined methodcontext_class' for nil:NilClass`.

This appears to be a side effect of #220, which stopped building Rails.application.assets when Rails.application.config.assets.compile was false. Because y'all merged #222, I'm guessing that breaking precompilation in this case was an accident rather than you intentionally deprecating the context_class injection interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions