Skip to content

Explicit path matching and path params for Pages#27

Merged
sbsoftware merged 2 commits intoreleases/v0.29.0from
feature/CR-104
Jan 1, 2026
Merged

Explicit path matching and path params for Pages#27
sbsoftware merged 2 commits intoreleases/v0.29.0from
feature/CR-104

Conversation

@sbsoftware
Copy link
Owner

@sbsoftware sbsoftware commented Jan 1, 2026

The previous path matching defaults for Pages was flawed as it always matched a resource-like path both with and without an ID path parameter, like it is for Resources. The issue is that a Page only supports a single view, so it cannot be responsible for an index and a detail view of a resource at the same time. If you want to serve two kinds of pages, you'll have to create two Page sub-classes or use a Resource.
With these changes, the default behavior of a Page is to just match the exact path derived from the path name (LegalNoticePage -> /legal_notice). This can be altered/extended via three macros:

  • root_path
    • Sets the matched path at the beginning (root_path "/foo")
  • path_param
    • Defines a path parameter with an optional matcher regex (path_param :id, /\d+/) and the end of the currently defined path
    • A method with the given name will be defined that returns the parsed parameter for an instance of the Page
  • nested_path
    • Adds a static segment to be matched at the end of the currently defined path

Example:

class PostsPage < ApplicationPage
  root_path "/posts" # redundant as it was already derived from the class name, could be left out
  path_param :id, /\d+/ # the digit-only regex is the default and could be left out
  nested_path "/comments" # leading or trailing slashes could be left out
end

PostsPage will then match paths of this kind: /posts/123/comments, with "123" begin returned by an #id method in the context of the page instance.

@sbsoftware sbsoftware merged commit d627847 into releases/v0.29.0 Jan 1, 2026
@sbsoftware sbsoftware deleted the feature/CR-104 branch January 1, 2026 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant