Sha256: df2af3ba24bd3bde1f4162cd50918bd34610abe8130f6a84c1b48d413c57087e

Contents?: true

Size: 929 Bytes

Versions: 1

Compression:

Stored size: 929 Bytes

Contents

module NeatPages::Implants::ActionControllerImplant
  extend ActiveSupport::Concern

  included do
    append_after_filter :set_pagination_header
    helper_method :pagination, :pagination_helpers
    rescue_from NeatPages::OutOfBound, :with => :render_out_of_bound
  end

  def paginate(options={})
    options.reverse_merge!(:per_page => 20)

    base_current_url = request.protocol + request.host + request.path_info

    neat_pages = NeatPages::Base.new(params[:page], options)
    neat_pages.activate_helpers(base_current_url, request.env['action_dispatch.request.query_parameters'])

    @_env['neat_pages'] = neat_pages
  end

  def pagination
    @_env['neat_pages']
  end

  def pagination_helpers
    pagination.helpers
  end

  def render_out_of_bound
    render :text => "out_of_bound", :status => 404
  end

  def set_pagination_header
    response.headers.merge! pagination.response_headers if pagination
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
neat-pages-0.0.2 lib/neat_pages/implants/action_controller_implant.rb