Created
January 4, 2021 18:10
-
-
Save mcls/530e8cd23fad2c1ed55784fdae596a8c to your computer and use it in GitHub Desktop.
Rails Routes class
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
# Make it easier to call rails routes from anywhere | |
class Routes | |
include Rails.application.routes.url_helpers | |
delegate :asset_path, :image_path, to: :controller_helpers | |
protected | |
def controller_helpers | |
ActionController::Base.helpers | |
end | |
class << self | |
def default_url_options | |
ActionMailer::Base.default_url_options | |
end | |
end | |
end | |
# Examples | |
ROUTER = Routes.new | |
ROUTER.root_path | |
# => "/" | |
ROUTER.asset_path("logo.png") | |
# => "/assets/logo-4877cac84535062a0d0a24c77c7a09bcb3290a4ec0beda3a401f6f60713bce5f.png" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment