mirror of
https://github.com/openSUSE/osem.git
synced 2026-02-05 11:41:06 -05:00
Use PictureUploader on Sponsor
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user