Sha256: d3439b7ac17600fecf381aacfa6f060557cd15d09c696a7697eb544c33f18000

Contents?: true

Size: 1.41 KB

Versions: 2

Compression:

Stored size: 1.41 KB

Contents

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

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

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


    ##
    # 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.url(:slide))
      self.width = geo.width
      self.height = geo.height
      self.save
    end

    ##
    # html options for the slide image_tag
    #
    def image_options
      if height.blank?
        save_image_dimensions
      end
      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

2 entries across 2 versions & 1 rubygems

Version Path
nivo-0.0.4 app/models/nivo/slide.rb
nivo-0.0.3 app/models/nivo/slide.rb