Created
February 19, 2024 09:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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