Sha256: c0668d533eff54a1abfcbcf4e108d1b8d617a208933369a5ad175514ea035a84

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

module Nivo
  class Slide < ActiveRecord::Base
    include Nivo::ManageSlides

    attr_accessible :caption, :url, :active, :lft, :rgt, :image

    has_attached_file :image, :styles => Nivo::Config.file['paperclip_options'].symbolize_keys

    ##
    # Save the image dimensions only when a new photo is uploaded
    #
    after_post_process :save_image_dimensions
    def save_image_dimensions
      geo = Paperclip::Geometry.from_file(image.queued_for_write[:slide])
      self.width = geo.width
      self.height = geo.height
    end

    ##
    # html options for the slide image_tag
    #
    def image_options
      image_options = {
        :height => height,
        :width => width,
        :class => "slide",
        :title => (caption if Nivo::Config.file['caption'] == true)
      }
    end

    ##
    # Find for slideshow
    #
    def self.rotate
      where("active = ?", true).order("position")
    end

    ##
    # Find for admin index
    #
    def self.page(search)
      if defined?(Dust::Application)
        with_permissions_to(:manage).search(search).order("position")
      else
        search(search).order("position")
      end
    end

    ##
    # currently used in self.page
    #
    def self.search(search)
      if search
        where("caption LIKE ?", "%#{search}%")
      else
        scoped
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nivo-0.0.2 app/models/nivo/slide.rb