Skip to content

Instantly share code, notes, and snippets.

@fractaledmind
Created February 19, 2024 09:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fractaledmind/8bdf3dd157a86ddd681717b5a3f7b3b2 to your computer and use it in GitHub Desktop.
Save fractaledmind/8bdf3dd157a86ddd681717b5a3f7b3b2 to your computer and use it in GitHub Desktop.
A singleton class for Rails apps to generate URLs easily from anywhere in their app.
# frozen_string_literal: true
module Router
class << self
include Rails.application.routes.url_helpers
def default_url_options
Rails.application.config.action_controller.default_url_options || {}
end
def asset_url(source, options = {})
ActionController::Base.helpers.asset_url(source, options.merge(default_url_options))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment