This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Adds behavior for getting, setting, and validating | |
| # images for any given model. Relies on RAILS_ROOT/config/image_definitions.rb | |
| module ImageHandling | |
| def self.included(base) | |
| base.class_eval do | |
| # Defines accessor names: if the class is Book, | |
| # names will be #book_images and #book_images= | |
| image_accessor_name = self.to_s.underscore + "_images" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create product images. | |
| @product.product_images.create(:label => 'main', :image => # Attachment object) | |
| @product.product_images.create(:label => 'header', :image => # Attachment object) | |
| # Access product images. | |
| @product.available_images('main') | |
| @product.available_images('header') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ProductImagesDefinitions = { | |
| 'main' => {:styles => {:large => "1200x600!", :medium => "600x300!"}, | |
| 'header' => {:styles => {:large => "400x600!", :medium => "200x300!"} | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Product < ActiveRecord::Base | |
| has_many :images, :class_name => "ProductImage" | |
| end | |
| class ProductImage < ActiveRecord::Base | |
| belongs_to :product |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| validates_presence_of :first_name, :if => :should_require_first_name? | |
| validates_uniqueness_of :url_slug, :if => :should_require_url_slug? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module SelectiveAttributeValidatable | |
| def self.included(base) | |
| base.send(:include, InstanceMethods) | |
| base.class_eval do | |
| alias_method_chain :update_attributes, :check | |
| end | |
| end |