mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-27 06:05:19 +00:00
Extract serializer helper method to service so the method isn't globally available
This commit is contained in:
@@ -13,11 +13,4 @@ module SerializerHelper
|
||||
|
||||
(serializer_attributes & model_attributes).map { |attr| "#{model.table_name}.#{attr}" }
|
||||
end
|
||||
|
||||
# Since Rails 4 has adjusted the way assets paths are handled, we have to access certain
|
||||
# asset-based helpers like this, when outside of a view or controller context.
|
||||
# See: https://stackoverflow.com/a/16609815
|
||||
def image_path(path)
|
||||
ActionController::Base.helpers.image_path(path)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# Represents the minimum details of an Enterprise when all shopfronts are being listed
|
||||
module Api
|
||||
class EnterpriseShopfrontListSerializer < ActiveModel::Serializer
|
||||
include SerializerHelper
|
||||
|
||||
attributes :name, :id, :latitude, :longitude, :is_primary_producer, :is_distributor,
|
||||
:path, :icon, :icon_font, :producer_icon_font, :address_id, :sells,
|
||||
:permalink
|
||||
@@ -21,7 +19,7 @@ module Api
|
||||
producer_shop: "map_003-producer-shop.svg",
|
||||
producer: "map_001-producer-only.svg",
|
||||
}
|
||||
image_path icons[enterprise.category]
|
||||
ImagePathService.image_path(icons[enterprise.category])
|
||||
end
|
||||
|
||||
def icon_font
|
||||
|
||||
10
app/services/image_path_service.rb
Normal file
10
app/services/image_path_service.rb
Normal file
@@ -0,0 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ImagePathService
|
||||
# Since Rails 4 has adjusted the way assets paths are handled, we have to access certain
|
||||
# asset-based helpers like this when outside of a view or controller context.
|
||||
# See: https://stackoverflow.com/a/16609815
|
||||
def self.image_path(path)
|
||||
ActionController::Base.helpers.image_path(path)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user