Created
September 19, 2012 03:46
-
-
Save adkron/3747567 to your computer and use it in GitHub Desktop.
Looking for feedback on trial run of tell don't ask
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
require 'mongoid' | |
module GluU | |
class Carousel | |
include Mongoid::Document | |
field :link, type: String | |
field :index, type: Integer | |
embeds_one :image, class_name: 'GluU::Carousel::Image', cascade_callbacks: true | |
delegate :url, to: :background_image, prefix: true | |
def background_image=(file) | |
background_image.replace file | |
end | |
def background_image | |
image || DefaultBackground.new(self) | |
end | |
def replace_background_image(file) | |
build_image.replace file | |
end | |
end | |
end |
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 GluU | |
class Carousel::DefaultBackground | |
attr_accessor :model | |
def initialize(model) | |
self.model = model | |
end | |
def url | |
'/assets/images/example-banner-1-f5d6421c4edb3f22071c9cd30c6c67ea.png' | |
end | |
def replace(file) | |
self.model.replace_background_image file | |
end | |
end | |
end |
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
require 'mongoid' | |
require 'carrierwave' | |
module GluU | |
class Carousel::Image | |
class Uploader < CarrierWave::Uploader::Base | |
include CarrierWave::ImageScience | |
process resize_to_fit: [560, 330] | |
end | |
include Mongoid::Document mount_uploader :file, Uploader | |
embedded_in :carousel, class_name: 'Carousel', inverse_of: :image | |
delegate :url, to: :file | |
def replace(file) | |
update_attributes file: file | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment