diff --git a/app/helpers/merged/view_helper.rb b/app/helpers/merged/view_helper.rb index f03bacf..59de1e6 100644 --- a/app/helpers/merged/view_helper.rb +++ b/app/helpers/merged/view_helper.rb @@ -7,7 +7,7 @@ module Merged def bg(section , clazz = "") attributes = {class: clazz} return attributes if section.image.blank? - img = asset_url( section.image.assert_name ) + img = asset_url( section.image.asset_name ) attributes["style"] = "background-image: url('#{img}');" if(section.option("fixed") == "on") attributes[:class] = attributes[:class] + " bg-fixed" @@ -18,7 +18,8 @@ module Merged # works for with sections and cards that respond to .image def image_for(element , classes = "") return "" if element.image.blank? - image_tag(element.image.assert_name , class: classes) + image = element.image + image_tag(image.asset_name , alt: image.name , class: classes ) end end diff --git a/app/models/merged/image.rb b/app/models/merged/image.rb index aa7bdf3..1d899da 100644 --- a/app/models/merged/image.rb +++ b/app/models/merged/image.rb @@ -70,15 +70,11 @@ module Merged Image.reload end - def assert_name - image_root + "/" + self.name + def asset_name + image_root + "/" + self.id.to_s end - def filename_old - full_filename = self.name + "." + self.type - Rails.root.join(asset_root, full_filename) - end - def filename_new + def full_filename full_filename = self.id.to_s + "." + self.type Rails.root.join(asset_root, full_filename) end diff --git a/app/views/merged/cards/index.haml b/app/views/merged/cards/index.haml index 4ea9e5f..fd47255 100644 --- a/app/views/merged/cards/index.haml +++ b/app/views/merged/cards/index.haml @@ -31,7 +31,7 @@ -if( card.image.blank? ) %p No image -else - = image_tag( card.image.assert_name , class: "p-3") + = image_for( card, "p-3") .basis-72.grow %h3.mt-4.text-lg.font-bold Fields = form_tag( card_url(card.id) , {method: :patch , class: "mx-auto mt-8 mb-0 max-w space-y-4" } ) do diff --git a/app/views/merged/images/index.haml b/app/views/merged/images/index.haml index 9893a6d..5e0daab 100644 --- a/app/views/merged/images/index.haml +++ b/app/views/merged/images/index.haml @@ -15,7 +15,7 @@ %strong.inline-block.rounded.bg-yellow-200.px-3.py-1.text-md.font-medium = aspect_ratio(image) .w-full.object-contain.h-72 - =image_tag(image.assert_name) + =image_tag(image.asset_name) .flex.justify-between.mb-8 %strong.inline-block.rounded.bg-orange-50.px-3.py-1.text-md.font-medium = "#{image.size}k" diff --git a/app/views/merged/sections/index.haml b/app/views/merged/sections/index.haml index 0866ba8..67e335a 100644 --- a/app/views/merged/sections/index.haml +++ b/app/views/merged/sections/index.haml @@ -44,7 +44,7 @@ = link_to(section_select_image_url(section.id)) do %h3.mt-4.text-lg.font-bold Image -if section.image - = image_tag( section.image.assert_name , class: "h-40") + = image_for( section , "h-40") -else %p No image .basis-52.grow diff --git a/app/views/merged/sections/show.haml b/app/views/merged/sections/show.haml index 1730e90..feff250 100644 --- a/app/views/merged/sections/show.haml +++ b/app/views/merged/sections/show.haml @@ -18,7 +18,7 @@ -if( @section.image.blank? ) %p No image -else - = image_tag( @section.image.assert_name , class: "my-3") + = image_for( @section , "my-3") = yellow_button("Change Image", section_select_image_url(@section.id)) = red_button( "Remove image", section_set_image_path( @section.id , image: "")) diff --git a/spec/models/merged/image_spec.rb b/spec/models/merged/image_spec.rb index 2f13814..2f9547b 100644 --- a/spec/models/merged/image_spec.rb +++ b/spec/models/merged/image_spec.rb @@ -5,20 +5,20 @@ module Merged let(:first) {Image.first} it "has Image.all" do - expect(Image.all.length).to be 41 + expect(Image.all.length).to be 17 end it "has image" do expect(first.class).to be Image end it "has name" do - expect(first.name).to eq "3dprinter_wide" + expect(first.name).to eq "common_spaces" end it "has height and width" do - expect(first.height).to eq 457 - expect(first.width).to eq 1279 + expect(first.height).to eq 300 + expect(first.width).to eq 560 end it "has height and width" do -# expect(first.aspect_ratio).to eq [13,5] + expect(first.aspect_ratio).to eq [13,7] end end