Store all images in a consistent path, compatible with development, and support S3 all round

This commit is contained in:
Rohan Mitchell
2014-07-17 11:07:34 +10:00
parent c40c586b6f
commit d7a5eb47f3
3 changed files with 34 additions and 8 deletions

View File

@@ -22,8 +22,23 @@ class Enterprise < ActiveRecord::Base
accepts_nested_attributes_for :address
accepts_nested_attributes_for :producer_properties, allow_destroy: true, reject_if: lambda { |pp| pp[:property_name].blank? }
has_attached_file :logo, :styles => { :medium => "300x300>", small: "180x180>", :thumb => "100x100>" }
has_attached_file :promo_image, :styles => { :large => "1200x260#", :thumb => "100x100>" }
has_attached_file :logo,
styles: { medium: "300x300>", small: "180x180>", thumb: "100x100>" },
url: '/images/enterprises/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprises/logos/:id/:style/:basename.:extension'
has_attached_file :promo_image,
styles: { large: "1200x260#", thumb: "100x100>" },
url: '/images/enterprises/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprises/promo_images/:id/:style/:basename.:extension'
validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
include Spree::Core::S3Support
supports_s3 :logo
supports_s3 :promo_image
validates_presence_of :name
validates_presence_of :address

View File

@@ -7,14 +7,24 @@ class EnterpriseGroup < ActiveRecord::Base
validates :description, presence: true
attr_accessible :name, :description, :long_description, :on_front_page, :enterprise_ids
attr_accessible :logo, :promo_image
attr_accessible :promo_image
has_attached_file :promo_image, styles: {large: "1200x260#"}
has_attached_file :logo,
styles: {medium: "100x100"},
url: '/images/enterprise_groups/logos/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/logos/:id/:style/:basename.:extension'
has_attached_file :promo_image,
styles: {large: "1200x260#"},
url: '/images/enterprise_groups/promo_images/:id/:style/:basename.:extension',
path: 'public/images/enterprise_groups/promo_images/:id/:style/:basename.:extension'
validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
validates_attachment_content_type :promo_image, :content_type => /\Aimage\/.*\Z/
attr_accessible :logo
has_attached_file :logo, styles: {medium: "100x100"}
validates_attachment_content_type :logo, :content_type => /\Aimage\/.*\Z/
include Spree::Core::S3Support
supports_s3 :logo
supports_s3 :promo_image
scope :by_position, order('position ASC')
scope :on_front_page, where(on_front_page: true)

View File

@@ -1,5 +1,6 @@
Spree::Taxon.class_eval do
self.attachment_definitions[:icon][:path] = 'app/public/spree/taxons/:id/:style/:basename.:extension'
self.attachment_definitions[:icon][:path] = 'public/images/spree/taxons/:id/:style/:basename.:extension'
self.attachment_definitions[:icon][:url] = '/images/spree/taxons/:id/:style/:basename.:extension'
# Indicate which filters should be used for this taxon