Use PictureUploader on Sponsor
This commit is contained in:
parent
0ad3ff01c3
commit
f1f5fc1cd4
6 changed files with 12 additions and 25 deletions
|
|
@ -49,7 +49,7 @@ module Admin
|
||||||
private
|
private
|
||||||
|
|
||||||
def sponsor_params
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ module SponsorsHelper
|
||||||
# returns the url to be used for logo on basis of sponsorship level position
|
# returns the url to be used for logo on basis of sponsorship level position
|
||||||
def get_logo(sponsor)
|
def get_logo(sponsor)
|
||||||
if sponsor.sponsorship_level.position == 1
|
if sponsor.sponsorship_level.position == 1
|
||||||
sponsor.logo.url(:first)
|
sponsor.picture.first.url
|
||||||
elsif sponsor.sponsorship_level.position == 2
|
elsif sponsor.sponsorship_level.position == 2
|
||||||
sponsor.logo.url(:second)
|
sponsor.picture.second.url
|
||||||
else
|
else
|
||||||
sponsor.logo.url(:others)
|
sponsor.picture.others.url
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,8 @@
|
||||||
class Sponsor < ActiveRecord::Base
|
class Sponsor < ActiveRecord::Base
|
||||||
belongs_to :sponsorship_level
|
belongs_to :sponsorship_level
|
||||||
belongs_to :conference
|
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,
|
mount_uploader :picture, PictureUploader, mount_on: :logo_file_name
|
||||||
content_type: [/jpg/, /jpeg/, /png/, /gif/],
|
|
||||||
size: { in: 0..500.kilobytes }
|
|
||||||
|
|
||||||
validates_presence_of :name, :website_url, :sponsorship_level, :logo
|
validates_presence_of :name, :website_url, :sponsorship_level
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -50,17 +50,17 @@ class PictureUploader < CarrierWave::Uploader::Base
|
||||||
|
|
||||||
version :first, if: :sponsor?
|
version :first, if: :sponsor?
|
||||||
version :first do
|
version :first do
|
||||||
process resize_to_fill: [320, 180]
|
process resize_and_pad: [320, 180, 'white']
|
||||||
end
|
end
|
||||||
|
|
||||||
version :second, if: :sponsor?
|
version :second, if: :sponsor?
|
||||||
version :second, from_version: :first do
|
version :second, from_version: :first do
|
||||||
process resize_to_fill: [320, 150]
|
process resize_and_pad: [320, 150, 'white']
|
||||||
end
|
end
|
||||||
|
|
||||||
version :others, if: :sponsor?
|
version :others, if: :sponsor?
|
||||||
version :others, from_version: :second do
|
version :others, from_version: :second do
|
||||||
process resize_to_fill: [320, 120]
|
process resize_and_pad: [320, 120, 'white']
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a white list of extensions which are allowed to be uploaded.
|
# 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|
|
= 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 :name
|
||||||
= f.input :description
|
= f.input :description
|
||||||
= image_tag f.object.logo(:thumb) if !f.object.logo.blank?
|
= image_tag f.object.picture.thumb.url if f.object.picture?
|
||||||
= f.input :logo
|
= f.input :picture
|
||||||
= f.input :website_url
|
= f.input :website_url
|
||||||
= f.input :sponsorship_level, collection: @conference.sponsorship_levels
|
= f.input :sponsorship_level, collection: @conference.sponsorship_levels
|
||||||
%p.text-right
|
%p.text-right
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
- @conference.sponsors.each do |sponsor|
|
- @conference.sponsors.each do |sponsor|
|
||||||
%tr
|
%tr
|
||||||
%td
|
%td
|
||||||
= image_tag(sponsor.logo(:thumb), width: '20%')
|
= image_tag(sponsor.picture.thumb.url, width: '20%')
|
||||||
%td
|
%td
|
||||||
= sponsor.name
|
= sponsor.name
|
||||||
%td
|
%td
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue