Skip to content

Instantly share code, notes, and snippets.

@amitpatelx
Created May 5, 2016 13:04
Show Gist options
  • Save amitpatelx/4994cbcca948f5a7e39b8b6d83d0e2a8 to your computer and use it in GitHub Desktop.
Save amitpatelx/4994cbcca948f5a7e39b8b6d83d0e2a8 to your computer and use it in GitHub Desktop.
Common Pagination inside ApplicationController - With Kaminari
def paginated(resources, per_page = 10)
resources.page(params[:page]).per(per_paget)
end
def search
if search_case.blank? || search_case == "All"
@documents = paginated(current_client.documents.includes(:projects))
else
@documents = paginated(Kaminari.paginate_array(selected_documents) # selected_documents is array
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment