sprockets-rails icon indicating copy to clipboard operation
sprockets-rails copied to clipboard

Sprockets::NotImplementedError: Custom asset_path helper is not implemented

Open cmalpeli opened this issue 9 years ago • 3 comments

I am getting the following when trying to precompile my assets locally

    RAILS_ENV=production bundle exec rake assets:precompile
    rake aborted!
    Sprockets::NotImplementedError: Custom asset_path helper is not implemented

    Extend your environment context with a custom method.

        environment.context_class.class_eval do
          def asset_path(path, options = {})
          end
        end
    /Users/cman/.rvm/gems/[email protected]/gems/sprockets-3.6.0/lib/sprockets/context.rb:198:in `asset_path'
    /Users/cman/.rvm/gems/[email protected]/gems/sprockets-3.6.0/lib/sprockets/context.rb:218:in `font_path'
    /Users/cman/.rvm/gems/[email protected]/gems/font-awesome-rails-4.6.1.0/app/assets/stylesheets/font-awesome.css.erb:15:in `_evaluate_template'

I can't for the life of me figure out why this is happening - any suggestions as how to tackle would be greatly appreciated!

I am able to precompile only if I add an initializer with the following:

 Rails.application.assets.context_class.class_eval do
      def asset_path(path, options = {})
        return ''
      end
    end

However, if I do so, when I push to my staging environment, the glyphicons from Bootstrap have an empty path and thus don't render:

font-face{font-family:'Glyphicons Halflings';src:url("");src:url("") format("embedded-opentype"),url("") format("woff"),url("") format("truetype"),url("")

cmalpeli avatar Apr 30 '16 21:04 cmalpeli

Can you please provide a sample application that reproduces the error?

rafaelfranca avatar Jun 27 '16 16:06 rafaelfranca

@cmalpeli did you include ActionView::Helpers::AssetUrlHelper somewhere in your code. I encountered the same error when I included that. Removing it solves my problem.

dnswus avatar Aug 02 '16 10:08 dnswus

@dnswus yup that was the issue! @rafaelfranca if you want to replicate the issue you can do something like include ActionView::Helpers::AssetUrlHelper in a Rake task and then try and precompile.....

cmalpeli avatar Aug 09 '16 20:08 cmalpeli