lib/carrierwave/jcrop/helpers.rb
# Form helper to render the preview of a cropped attachment.
# Loads the actual image. Previewbox has no constraints on dimensions, image is renedred at full size.
# By default box size is 100x100. Size can be customized by setting the :width and :height option.
# If you override one of width/height you must override both.
# By default original image is rendered. Specific version can be specified by passing version option
#
#   previewbox :avatar
#   previewbox :avatar, width: 200, height: 200
#   previewbox :avatar, version: :medium
#
# @param attachment [Symbol] attachment name
# @param opts [Hash] specify version or width and height options
Form helper to render the preview of a cropped attachment.
Loads the actual image. Previewbox has no constraints on dimensions, image is renedred at full size.
By default box size is 100x100. Size can be customized by setting the :width and :height option.
If you override one of width/height you must override both.
By default original image is rendered. Specific version can be specified by passing version option


Form helper to render the preview of a cropped attachment . Loads the actual image . Previewbox has no constraints on dimensions image is renedred at full size . By default box size is 100x100 . Size can be customized by setting the : width and : height option . If you override one of width / height you must override both . By default original image is rendered . Specific version can be specified by passing version option
def previewbox(attachment, opts = {})
        attachment = attachment.to_sym
        if(self.object.send(attachment).class.ancestors.include? CarrierWave::Uploader::Base )
          model_name = self.object.class.name.downcase.split("::").last
          width, height = 100, 100
          if(opts[:width] && opts[:height])
            width, height = opts[:width].round, opts[:height].round
          end
          wrapper_attributes = {id: "#{model_name}_#{attachment}_previewbox_wrapper", style: "width:#{width}px; height:#{height}px; overflow:hidden"}
          if opts[:version]
            img = self.object.send(attachment).url(opts[:version])
          else
            img = self.object.send(attachment).url
          end
          preview_image = @template.image_tag(img, id: "#{model_name}_#{attachment}_previewbox")
          @template.content_tag(:div, preview_image, wrapper_attributes)
        end
      end
def previewbox ( attachment , opts = { } ) attachment = attachment . to_sym if ( self . object . send ( attachment ) . class . ancestors . include? CarrierWave :: Uploader :: Base ) model_name = self . object . class . name . downcase . split ( "::" ) . last width , height = 100 , 100 if ( opts [ :width ] && opts [ :height ] ) width , height = opts [ :width ] . round , opts [ :height ] . round end wrapper_attributes = { id : "#{model_name}_#{attachment}_previewbox_wrapper" , style : "width:#{width}px; height:#{height}px; overflow:hidden" } if opts [ :version ] img = self . object . send ( attachment ) . url ( opts [ :version ] ) else img = self . object . send ( attachment ) . url end preview_image = @template . image_tag ( img , id : "#{model_name}_#{attachment}_previewbox" ) @template . content_tag ( :div , preview_image , wrapper_attributes ) end end
Form helper to render the preview of a cropped attachment.
Form helper to render the preview of a cropped attachment .
## Fixes Issue #1 : Colons in html id attributes with Namespaced Models
attachment
None
opts
specify version or width and height options
specify version or width and height options