Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alexandreruban/pagination-engine-screencast
Learn to create Ruby on Rails engines by building a pagination engine.
https://github.com/alexandreruban/pagination-engine-screencast
Last synced: 3 days ago
JSON representation
Learn to create Ruby on Rails engines by building a pagination engine.
- Host: GitHub
- URL: https://github.com/alexandreruban/pagination-engine-screencast
- Owner: alexandreruban
- License: mit
- Created: 2022-04-22T09:00:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-25T12:27:59.000Z (over 2 years ago)
- Last Synced: 2024-12-21T05:50:32.314Z (16 days ago)
- Language: Ruby
- Homepage:
- Size: 25.4 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE
Awesome Lists containing this project
README
# Paginate
This repository is the source code of a pagination engine we will build in a screencast. The goal of the screencast is to learn to create Ruby on Rails engines and more specifically:
- Create a Rails engine with the `rails plugin new` command.
- Use the `Railtie` class to extend the Ruby on Rails framework.
- Test our Rails engine with the help of the `test/dummy` application.By the end of the screencast, you should be able to create your own Rails engines!
## Usage
Our pagination engine provides the `set_page_and_extract_portion_from` method you can use inside your controllers to paginate a collection of records base on the `?page=n` query string:
```rb
# app/controllers/recordings_controller.rbclass RecordingsController < ApplicationController
def index
@recordings = set_page_and_extract_portion_from(Recording.all)
end
end
```In the view, it gives you access to a `@page` object you can use to link to the previous/next page:
```erb
<%# app/views/recordings/index.html.erb %>Recordings
<%= render @recordings %>
<% unless @page.first? %>
<%= link_to "Previous page", recordings_path(page: @page.previous_param) %>
<% end %><% unless @page.last? %>
<%= link_to "Next page", recordings_path(page: @page.next_param) %>
<% end %>
```## Credits
This engine's API is heavily inspired by the [geared_pagination][] open-source gem developed by the Basecamp team. Check the code to see how a real-world pagination engine works!
[geared_pagination]: https://github.com/basecamp/geared_pagination