Module: RailsMetricsHelper::Pagination

Included in:
RailsMetricsHelper
Defined in:
app/helpers/rails_metrics_helper.rb

Instance Method Summary collapse

Instance Method Details

Show next link for pagination


23
24
25
26
# File 'app/helpers/rails_metrics_helper.rb', line 23

def next_link
  link = url_for(params.merge(:offset => @offset + @limit))
  link_to_if(@offset + @limit < @metrics_count, "Next", link)
end

#paginate!Object

Add pagination to footlinks


29
30
31
32
33
34
# File 'app/helpers/rails_metrics_helper.rb', line 29

def paginate!
  content_for :rails_metrics_footlinks do
    (:p, [previous_link, pagination_info, next_link].join(" | ")) <<
    (:p, "Show per page: #{show_per_page [10, 25, 50, 100]}")
  end
end

#pagination_infoObject

Returns information about pagination


4
5
6
7
# File 'app/helpers/rails_metrics_helper.rb', line 4

def pagination_info
  maximum = [@metrics_count, @offset + @limit].min
  "#{@offset + 1} - #{maximum} of #{@metrics_count}"
end

Shows previous link for pagination


17
18
19
20
# File 'app/helpers/rails_metrics_helper.rb', line 17

def previous_link
  link = url_for(params.merge(:offset => [0, @offset - @limit].max))
  link_to_if(@offset > 0, "Previous", link)
end

#show_per_page(values) ⇒ Object

Shows per page links


10
11
12
13
14
# File 'app/helpers/rails_metrics_helper.rb', line 10

def show_per_page(values)
  values.map do |i|
    link_to_unless(@limit == i, i.to_s, url_for(params.merge(:limit => i)))
  end.join(" | ").html_safe
end