Simplify calling #url_for in models

This commit is contained in:
Matt-Yorkley
2023-05-04 01:01:12 +01:00
parent a898915724
commit 551d0d3a93
3 changed files with 8 additions and 10 deletions

View File

@@ -14,4 +14,8 @@ class ApplicationRecord < ActiveRecord::Base
def self.image_service
ENV["S3_BUCKET"].present? ? :amazon_public : :local
end
def url_for(*args)
Rails.application.routes.url_helpers.url_for(*args)
end
end

View File

@@ -297,25 +297,19 @@ class Enterprise < ApplicationRecord
def logo_url(name)
return unless logo.variable?
Rails.application.routes.url_helpers.url_for(
logo.variant(name)
)
url_for(logo.variant(name))
end
def promo_image_url(name)
return unless promo_image.variable?
Rails.application.routes.url_helpers.url_for(
promo_image.variant(name)
)
url_for(promo_image.variant(name))
end
def white_label_logo_url(name = :default)
return unless white_label_logo.variable?
Rails.application.routes.url_helpers.url_for(
white_label_logo.variant(name)
)
url_for(white_label_logo.variant(name))
end
def website

View File

@@ -26,7 +26,7 @@ module Spree
def url(size)
return unless attachment.attached?
Rails.application.routes.url_helpers.url_for(variant(size))
url_for(variant(size))
end
# if there are errors from the plugin, then add a more meaningful message