Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6832371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:51:02+00:00 2026-05-26T22:51:02+00:00

I have a little Sinatra app including this module: module Sprockets module Helpers def

  • 0

I have a little Sinatra app including this module:

module Sprockets
  module Helpers
    def asset_path(source)
      "/assets/#{Environment.instance.find_asset(source).digest_path}"
    end

    def sprockets
      Environment.instance.call(env)
    end
  end

  class << self
    def precompile
      dir = 'public/assets'

      FileUtils.rm_rf(dir, secure: true)
      ::Sprockets::StaticCompiler.new(Environment.instance, 'public/assets', [/\.(png|jpg)$/, /^(application|ie)\.(css|js)$/]).compile
    end
  end

  class Environment < ::Sprockets::Environment
    include Singleton

    def initialize
      super
      %w[app lib vendor].each do |dir|
        %w[images javascripts stylesheets].each do |type|
          path = File.join(root, dir, 'assets', type)
          append_path(path) if File.exist?(path)
        end
      end

      js_compressor = Uglifier.new
      css_compressor = YUI::CssCompressor.new

      context_class.instance_eval do
        include Helpers
      end
    end
  end
end

and with following route defined:

get('/assets/*') do
  sprockets # Defined in the module above
end

Everything works just great, assets are loaded and displayed properly on my local machine using pow. But on Heroku no single asset is loaded, the server just returns 404 for every asset file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:51:03+00:00Added an answer on May 26, 2026 at 10:51 pm

    Simplified the module and now it works! Weird…

    class Assets < Sprockets::Environment
      class << self
        def instance(root = nil)
          @instance ||= new(root)
        end
      end
    
      def initialize(root)
        super
    
        %w[app lib vendor].each do |dir|
          %w[images javascripts stylesheets].each do |type|
            path = File.join(root, dir, 'assets', type)
            self.append_path(path) if File.exist?(path)
          end
        end
    
        self.css_compressor = YUI::CssCompressor.new
        self.js_compressor = Uglifier.new
    
        context_class.instance_eval do
          include Helpers
        end
      end
    
      def precompile
        dir = 'public/assets'
    
        FileUtils.rm_rf(dir, secure: true)
        Sprockets::StaticCompiler.new(self, 'public/assets', ['*']).compile
      end
    
      module Helpers
        def asset_path(source)
          "/assets/#{Assets.instance.find_asset(source).digest_path}"
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have little problem with boost::asio library. My app receive and process data asynchronously,
I have little question about how web browser retrieve webpage? I know this User
I have a MainMenu in my app and I would like to have little
I am learning Rails and have very little idea about Sinatra & Merb. I
I have little Silverlight app that needs to make queries to server, is it
I know this question is simple, but I have little experience with arrays and
Okay since I have little experience with this stuff and the Facebook documentation is
I have been working on this for a while now and, unfortunately have little
Hey most of my issue has been solved but i have little problem This
Apologies if the question appears ambiguous, I have little experience in this area and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.