Skip to content

Commit

Permalink
Use file mime type for picture by format select
Browse files Browse the repository at this point in the history
Active storage has the mime type stored not the extension.
  • Loading branch information
tvdeyen committed Apr 12, 2022
1 parent 6280feb commit 594b0a7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/models/alchemy/picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ def self.preprocessor_class=(klass)
scope :recent, -> { where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at) }
scope :deletable, -> { where("#{table_name}.id NOT IN (SELECT picture_id FROM #{EssencePicture.table_name})") }
scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: { id: nil }) }
scope :by_file_format, ->(format) { where(image_file_format: format) }
scope :by_file_format, ->(file_format) {
with_attached_image_file.joins(:image_file_blob).where(active_storage_blobs: { content_type: file_format })
}

# Class methods

Expand All @@ -111,14 +113,10 @@ def url_class=(klass)
end

def alchemy_resource_filters
file_types = file_formats.map do |format|
MiniMime.lookup_by_content_type(format)&.extension
end

[
{
name: :by_file_format,
values: file_types,
values: file_formats,
},
{
name: :misc,
Expand Down
1 change: 1 addition & 0 deletions config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ en:
by_file_format:
name: File Type
values:
<<: *mime_types
gif: GIF Image
jpeg: JPG Image
png: PNG Image
Expand Down

0 comments on commit 594b0a7

Please sign in to comment.