Skip to content

Commit 950dcd9

Browse files
committed
Add sample turbo frame pagination
1 parent c9bf6f5 commit 950dcd9

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

README.md

+10-18
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
11
# README
22

3-
This README would normally document whatever steps are necessary to get the
4-
application up and running.
3+
This is a sample Rails application that simply demonstrates a turbo frame that promotes navigation to page visit, i.e., it restricts the page changes to the frame, but updates the URL as it changes on the frame.
54

6-
Things you may want to cover:
5+
## Running locally
76

8-
* Ruby version
7+
```
8+
bundle install
9+
rails server
10+
```
911

10-
* System dependencies
12+
## Testing
1113

12-
* Configuration
13-
14-
* Database creation
15-
16-
* Database initialization
17-
18-
* How to run the test suite
19-
20-
* Services (job queues, cache servers, search engines, etc.)
21-
22-
* Deployment instructions
23-
24-
* ...
14+
1. Visit http://localhost:3000
15+
2. Click next and previous pagination links
16+
3. Notice that the current URL changes on the address bar

app/controllers/hello_controller.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
class HelloController < ApplicationController
3+
def index
4+
@page = (params[:page] || 1).to_i
5+
end
6+
end

app/views/hello/index.html.erb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
<turbo-frame id="pagination" data-turbo-action="advance">
3+
<h1>Page <%= @page %></h1>
4+
<p>You are currently on page <%= @page %>.</p>
5+
6+
<%= link_to 'Previous', root_path(page: @page - 1), style: @page <= 1 ? 'visibility:hidden' : '' %>
7+
8+
<%= link_to 'Next', root_path(page: @page + 1) %>
9+
</turbo-frame>

0 commit comments

Comments
 (0)