lib/papercrop/helpers.rb
# Form helper to render the cropping preview box of an attachment.
# Box width can be handled by setting the :width option.
# Width is 100 by default. Height is calculated by the aspect ratio.
#
#   crop_preview :avatar
#   crop_preview :avatar, :width => 150
#
# @param attachment [Symbol] attachment name
# @param opts [Hash]
Form helper to render the cropping preview box of an attachment.
Box width can be handled by setting the :width option.
Width is 100 by default. Height is calculated by the aspect ratio.

crop_preview :avatar
crop_preview :avatar, :width => 150
Form helper to render the cropping preview box of an attachment . Box width can be handled by setting the : width option . Width is 100 by default . Height is calculated by the aspect ratio . crop_preview : avatar crop_preview : avatar : width = > 150
def crop_preview(attachment, opts = {})
      attachment = attachment.to_sym
      width      = opts[:width] || 100
      height     = (width / self.object.send(:"#{attachment}_aspect")).round
      if self.object.send(attachment).class == Paperclip::Attachment
        wrapper_options = {
          :id    => "#{attachment}_crop_preview_wrapper",
          :style => "width:#{width}px; height:#{height}px; overflow:hidden"
        }
        image_options = {
          :id    => "#{attachment}_crop_preview",
          :style => "max-width:none; max-height:none"
        }
        preview_image = @template.image_tag(self.object.send(attachment).url, image_options)
        @template.content_tag(:div, preview_image, wrapper_options)
      end
    end
def crop_preview ( attachment , opts = { } ) attachment = attachment . to_sym width = opts [ :width ] || 100 height = ( width / self . object . send ( :" #{ attachment } _aspect " ) ) . round if self . object . send ( attachment ) . class == Paperclip :: Attachment wrapper_options = { :id => "#{attachment}_crop_preview_wrapper" , :style => "width:#{width}px; height:#{height}px; overflow:hidden" } image_options = { :id => "#{attachment}_crop_preview" , :style => "max-width:none; max-height:none" } preview_image = @template . image_tag ( self . object . send ( attachment ) . url , image_options ) @template . content_tag ( :div , preview_image , wrapper_options ) end end
Form helper to render the cropping preview box of an attachment.
Form helper to render the cropping preview box of an attachment .
attachment
None
opts
<not_specific>
<not_specific>
None