Class: Nivo::Slide

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ManageSlides
Defined in:
app/models/nivo/slide.rb

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.page(search) ⇒ Object

Find for admin index



48
49
50
51
52
53
54
# File 'app/models/nivo/slide.rb', line 48

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

.rotateObject

Find for slideshow



41
42
43
# File 'app/models/nivo/slide.rb', line 41

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

.search(search) ⇒ Object

currently used in self.page



59
60
61
62
63
64
65
# File 'app/models/nivo/slide.rb', line 59

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

Instance Method Details

#image_optionsObject

html options for the slide image_tag



26
27
28
29
30
31
32
33
34
35
36
# File 'app/models/nivo/slide.rb', line 26

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

#save_image_dimensionsObject

Save the image dimensions only when a new photo is uploaded

after_post_process :save_image_dimensions



16
17
18
19
20
21
# File 'app/models/nivo/slide.rb', line 16

def save_image_dimensions
  geo = Paperclip::Geometry.from_file(image.url(:slide))
  self.width = geo.width
  self.height = geo.height
  self.save
end