diff --git a/app/controllers/admin/sponsors_controller.rb b/app/controllers/admin/sponsors_controller.rb index b7164900..2ee51762 100644 --- a/app/controllers/admin/sponsors_controller.rb +++ b/app/controllers/admin/sponsors_controller.rb @@ -49,7 +49,7 @@ module Admin private def sponsor_params - params.require(:sponsor).permit(:name, :description, :website_url, :logo, :sponsorship_level_id, :conference_id) + params.require(:sponsor).permit(:name, :description, :website_url, :picture, :picture_cache, :sponsorship_level_id, :conference_id) end end end diff --git a/app/helpers/sponsors_helper.rb b/app/helpers/sponsors_helper.rb index e827c1fe..4a21c9cd 100644 --- a/app/helpers/sponsors_helper.rb +++ b/app/helpers/sponsors_helper.rb @@ -2,11 +2,11 @@ module SponsorsHelper # returns the url to be used for logo on basis of sponsorship level position def get_logo(sponsor) if sponsor.sponsorship_level.position == 1 - sponsor.logo.url(:first) + sponsor.picture.first.url elsif sponsor.sponsorship_level.position == 2 - sponsor.logo.url(:second) + sponsor.picture.second.url else - sponsor.logo.url(:others) + sponsor.picture.others.url end end end diff --git a/app/models/sponsor.rb b/app/models/sponsor.rb index 6b255886..7a843e63 100644 --- a/app/models/sponsor.rb +++ b/app/models/sponsor.rb @@ -1,21 +1,8 @@ class Sponsor < ActiveRecord::Base belongs_to :sponsorship_level belongs_to :conference - has_attached_file :logo, - styles: { thumb: '100x100>', - first: '320x180>', - second: '320x150>', - others: '320x120>' }, - # places logo on a white background to maintain size - convert_options: { - first: '-background white -gravity center -extent 320x180', - second: '-background white -gravity center -extent 320x150', - others: '-background white -gravity center -extent 320x120' - } - validates_attachment_content_type :logo, - content_type: [/jpg/, /jpeg/, /png/, /gif/], - size: { in: 0..500.kilobytes } + mount_uploader :picture, PictureUploader, mount_on: :logo_file_name - validates_presence_of :name, :website_url, :sponsorship_level, :logo + validates_presence_of :name, :website_url, :sponsorship_level end diff --git a/app/uploaders/picture_uploader.rb b/app/uploaders/picture_uploader.rb index ac25565b..d4ad2a60 100644 --- a/app/uploaders/picture_uploader.rb +++ b/app/uploaders/picture_uploader.rb @@ -50,17 +50,17 @@ class PictureUploader < CarrierWave::Uploader::Base version :first, if: :sponsor? version :first do - process resize_to_fill: [320, 180] + process resize_and_pad: [320, 180, 'white'] end version :second, if: :sponsor? version :second, from_version: :first do - process resize_to_fill: [320, 150] + process resize_and_pad: [320, 150, 'white'] end version :others, if: :sponsor? version :others, from_version: :second do - process resize_to_fill: [320, 120] + process resize_and_pad: [320, 120, 'white'] end # Add a white list of extensions which are allowed to be uploaded. diff --git a/app/views/admin/sponsors/_form.html.haml b/app/views/admin/sponsors/_form.html.haml index 5ec2fbd0..ca78d8a5 100644 --- a/app/views/admin/sponsors/_form.html.haml +++ b/app/views/admin/sponsors/_form.html.haml @@ -11,8 +11,8 @@ = semantic_form_for(@sponsor, :url => (@sponsor.new_record? ? admin_conference_sponsors_path : admin_conference_sponsor_path(@conference.short_title, @sponsor))) do |f| = f.input :name = f.input :description - = image_tag f.object.logo(:thumb) if !f.object.logo.blank? - = f.input :logo + = image_tag f.object.picture.thumb.url if f.object.picture? + = f.input :picture = f.input :website_url = f.input :sponsorship_level, collection: @conference.sponsorship_levels %p.text-right diff --git a/app/views/admin/sponsors/index.html.haml b/app/views/admin/sponsors/index.html.haml index d6364cb0..1c8f1077 100644 --- a/app/views/admin/sponsors/index.html.haml +++ b/app/views/admin/sponsors/index.html.haml @@ -19,7 +19,7 @@ - @conference.sponsors.each do |sponsor| %tr %td - = image_tag(sponsor.logo(:thumb), width: '20%') + = image_tag(sponsor.picture.thumb.url, width: '20%') %td = sponsor.name %td