Class: Lentil::ImagesController

Inherits:
ApplicationController show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/controllers/lentil/images_controller.rb

Instance Method Summary collapse

Instance Method Details

#animateObject



51
52
53
# File 'app/controllers/lentil/images_controller.rb', line 51

def animate
  @images = Image.approved.blend
end

#iframeObject



64
65
66
67
68
# File 'app/controllers/lentil/images_controller.rb', line 64

def iframe
  @images = Image.includes(:user).approved.recent.limit(125)
  @smallest_width = numeric_string?(params['smallest_width']) ? params['smallest_width'] : 64
  render :action => "iframe", :layout => "lentil/iframe"
end

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/lentil/images_controller.rb', line 5

def index
    respond_to do |format|
      format.html { @images = Image.includes(:user).approved.recent.search(params[:page]) }
      format.atom { @images = Image.includes(:user).approved.recent.limit(200) }
      format.rss { @images = Image.includes(:user).approved.recent.limit(200) }
    end
end

#numeric_string?(str) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/controllers/lentil/images_controller.rb', line 60

def numeric_string?(str)
  Float(str) != nil rescue false
end


23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/lentil/images_controller.rb', line 23

def popular
  @title = "Popular Images"
  # show about 10% of image ordered by popularity
  number_to_show = (Image.approved.count*0.1).round
  respond_to do |format|
    format.html { @images = Image.includes(:user).approved.popular.search(params[:page], number_to_show) }
    format.atom { @images = Image.includes(:user).approved.popular.limit(number_to_show) }
    format.rss { @images = Image.includes(:user).approved.popular.limit(number_to_show) }
  end
  render :action => "index"
end

#recentObject



13
14
15
16
17
18
19
20
21
# File 'app/controllers/lentil/images_controller.rb', line 13

def recent
    @title = "Recent Images"
    respond_to do |format|
      format.html { @images = Image.includes(:user).approved.recent.search(params[:page]) }
      format.atom { @images = Image.includes(:user).approved.recent.limit(200) }
      format.rss { @images = Image.includes(:user).approved.recent.limit(200) }
    end
    render :action => "index"
end

#showObject



45
46
47
48
49
# File 'app/controllers/lentil/images_controller.rb', line 45

def show
  @image = Image.approved.find(params[:id])
  short_title = truncate(@image.description, :length => 50, :separator => ' ')
  @title = "#{short_title}, #{@image.user.user_name}, Image #{@image.id}"
end

#staff_picksObject



35
36
37
38
39
40
41
42
43
# File 'app/controllers/lentil/images_controller.rb', line 35

def staff_picks
  @title = "Staff Picks"
  respond_to do |format|
    format.html { @images = Image.includes(:user).approved.staff_picks.search(params[:page]) }
    format.atom { @images = Image.includes(:user).approved.staff_picks.limit(200)}
    format.rss { @images = Image.includes(:user).approved.staff_picks.limit(200)}
  end
  render :action => "index"
end

#staff_picks_animateObject



55
56
57
58
# File 'app/controllers/lentil/images_controller.rb', line 55

def staff_picks_animate
  @images = Image.approved.staff_picks.limit(100)
  render 'animate'
end