Module: Kaminari::ActionViewExtension::InstanceMethods
- Defined in:
- lib/kaminari/helpers/action_view_extension.rb
Instance Method Summary collapse
-
#link_to_next_page(scope, name, options = {}, &block) ⇒ Object
A simple “Twitter like” pagination link that creates a link to the next page.
-
#paginate(scope, options = {}, &block) ⇒ Object
A helper that renders the pagination links.
Instance Method Details
#link_to_next_page(scope, name, options = {}, &block) ⇒ Object
A simple “Twitter like” pagination link that creates a link to the next page.
Examples
Basic usage:
<%= link_to_next_page @items, 'Next Page' %>
Ajax:
<%= link_to_next_page @items, 'Next Page', :remote => true %>
By default, it renders nothing if there are no more results on the next page. You can customize this output by passing a block.
<%= link_to_next_page @users, 'Next Page' do %>
<span>No More Pages</span>
<% end %>
41 42 43 44 45 46 47 |
# File 'lib/kaminari/helpers/action_view_extension.rb', line 41 def link_to_next_page(scope, name, = {}, &block) params = .delete(:params) || {} param_name = .delete(:param_name) || Kaminari.config.param_name link_to_unless scope.last_page?, name, params.merge(param_name => (scope.current_page + 1)), .merge(:rel => 'next') do block.call if block end end |
#paginate(scope, options = {}, &block) ⇒ Object
A helper that renders the pagination links.
<%= paginate @articles %>
Options
-
:window
- The “inner window” size (4 by default). -
:outer_window
- The “outer window” size (0 by default). -
:left
- The “left outer window” size (0 by default). -
:right
- The “right outer window” size (0 by default). -
:params
- url_for parameters for the links (:controller, :action, etc.) -
:param_name
- parameter name for page number in the links (:page by default) -
:remote
- Ajax? (false by default) -
:ANY_OTHER_VALUES
- Any other hash key & values would be directly passed into each tag as :locals value.
19 20 21 22 |
# File 'lib/kaminari/helpers/action_view_extension.rb', line 19 def paginate(scope, = {}, &block) paginator = Kaminari::Helpers::Paginator.new self, .reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false) paginator.to_s end |