app/decorators/photo_album_decorator.rb
class PhotoAlbumDecorator < Draper::Base
decorates :photo_album
# Accessing Helpers
# You can access any helper via a proxy
#
# Normal Usage: helpers.number_to_currency(2)
# Abbreviated : h.number_to_currency(2)
#
# Or, optionally enable "lazy helpers" by including this module:
# include Draper::LazyHelpers
# Then use the helpers with no proxy:
# number_to_currency(2)
# Defining an Interface
# Control access to the wrapped subject's methods using one of the following:
#
# To allow only the listed methods (whitelist):
# allows :method1, :method2
#
# To allow everything except the listed methods (blacklist):
# denies :method1, :method2
# Presentation Methods
# Define your own instance methods, even overriding accessors
# generated by ActiveRecord:
#
# def created_at
# h.content_tag :span, time.strftime("%a %m/%d/%y"),
# :class => 'timestamp'
# end
def sorted_photos
photos.by_main
end
def sorted_photos_with_limit(limit = nil)
sorted_photos.limit(limit)
end
def main_photo
sorted_photos.first
end
def preview_photo(style = nil)
main_photo.image_url(style) if main_photo
end
end