一键导入
pagination-patterns
Pagination in Rails using will_paginate. Use when adding page navigation to index actions or API endpoints.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Pagination in Rails using will_paginate. Use when adding page navigation to index actions or API endpoints.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | pagination-patterns |
| description | Pagination in Rails using will_paginate. Use when adding page navigation to index actions or API endpoints. |
| allowed-tools | Read, Write, Edit, Bash, Glob, Grep |
# Gemfile
gem "will_paginate"
# Controller
def index
@page = params[:page] || 1
@posts = Post.published.order(created_at: :desc)
.paginate(page: @page, per_page: 25)
end
Works on any ActiveRecord relation — scopes, joins, includes, anything:
@messages = User.role_support.last
.unread_messages
.order(:conversation_id)
.paginate(page: @page, per_page: 25)
<%= render @posts %>
<%= will_paginate @posts %>
def index
@posts = Post.published.order(created_at: :desc)
.paginate(page: params[:page], per_page: 25)
render json: {
posts: PostSerializer.render(@posts),
page: @posts.current_page,
total_pages: @posts.total_pages,
total: @posts.total_entries
}
end
# spec/requests/posts_spec.rb
RSpec.describe "Posts", type: :request do
let!(:posts) { create_list(:post, 30, :published) }
it "renders first page with pagination nav" do
get posts_path
expect(response).to have_http_status(:ok)
# will_paginate renders a <div class="will-paginate"> nav when multiple pages exist
expect(response.body).to include("will-paginate")
# Only 25 of 30 posts on page 1 — last 5 posts appear only on page 2
expect(response.body).not_to include(posts.last.title)
end
it "renders page 2 with remaining records" do
get posts_path, params: { page: 2 }
expect(response).to have_http_status(:ok)
expect(response.body).to include(posts.last.title)
end
end
# For API endpoints — parse JSON response
RSpec.describe "Posts API", type: :request do
before { create_list(:post, 30, :published) }
it "paginates results" do
get posts_path, as: :json
json = response.parsed_body
expect(json["posts"].size).to eq(25)
expect(json["total_pages"]).to eq(2)
expect(json["total"]).to eq(30)
end
end
gem "will_paginate" in Gemfile.paginate(page: params[:page], per_page: N) on the relationwill_paginate @collection in the viewincludes() on the relation to prevent N+1Create new Rails skills, modify and improve existing ones. Use when the user wants to build a new skill from scratch, improve an existing skill, capture a workflow as a reusable skill, or turn a repeated Rails pattern into a skill. Triggers on: "create a skill", "new skill for", "turn this into a skill", "skill for X", "add a skill", "improve this skill".
Bulk insert, upsert, and update operations in Rails - insert_all, upsert_all, update_all, find_in_batches, and activerecord-import. Use when processing large datasets, imports, or batch writes that would be too slow with individual ActiveRecord saves.
Fan-out scheduler pattern - one orchestrator job dispatches many worker jobs efficiently using perform_all_later and Set-based filtering. Use when processing large external datasets, scheduled syncs, or any operation that reads N records and needs to dispatch N background jobs without blocking.
Queue-level concurrency controls in Solid Queue to respect external API rate limits. Use when a job calls a third-party API with burst or concurrency limits, or when you need to cap how many instances of a job type run in parallel across all workers.
Configures Solid Queue for background jobs in Rails 8. Use when setting up background processing, creating background jobs, configuring job queues, or migrating from Sidekiq to Solid Queue.
Rails error handling - custom exception hierarchy, rescue_from in controllers, consistent API error responses, Sentry integration, and the bridge between dry-monads Failure() and HTTP status codes.