Skip to content

Commit

Permalink
WIP fix ordering of attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
richardTowers committed Nov 6, 2024
1 parent 02c51c5 commit 686a95f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions app/models/concerns/image_kind.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ module ImageKind
def assign_attributes(attributes)
# It's important that the image_kind attribute is assigned first, as it is intended to be used by
# carrierwave uploaders when they are mounted to work out which image versions to use.
image_kind_attributes = attributes.slice(:image_kind)
attributes.reverse_merge!(image_kind_attributes) unless image_kind_attributes.empty?

super
image_kind = attributes.delete(:image_kind)
ordered_attributes = if image_kind.present?
{ image_kind:, **attributes }
else
attributes
end
super ordered_attributes
end

def image_kind
attributes.fetch(:image_kind, "default")
attributes.fetch("image_kind", "default")
end

def image_kind_config
Expand Down

0 comments on commit 686a95f

Please sign in to comment.