Skip to content

Fix next/previous raising for resources without the grouping field - #222

Merged
eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/adjacency-without-within
Nov 2, 2026
Merged

eelcoj merged 1 commit into
Rails-Designer:mainfrom
pcbeingused333:fix/adjacency-without-within

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

next and previous raise NoMethodError (undefined method 'to_sym' for nil) when a resource doesn't have the attribute that adjacent_by ... within: groups by (for example an article without section: in its front matter) and within: is given as an ordered hash such as {section: SECTIONS}.

Cause: in Perron::Resource::Adjacency, the ordered lookup does grouping_order.index(group_value.to_s) || grouping_order.index(group_value.to_sym). With a nil group value the second call raises. It appears in both next and previous.

Fix: use group_value.to_s.to_sym in both places. A resource without the field now gets the same position as a value missing from the list (Float::INFINITY), so it sorts after the listed groups instead of raising.

Test: new case in test/perron/resource/adjacency_test.rb with a small resource class that has one ungrouped entry; it checks next and previous around it.

Disclosure: this change was prepared with the assistance of an AI coding agent (Claude) and submitted by the account owner.

With an ordered adjacent_by within: option, a resource lacking the grouping
attribute made group_value nil, and nil.to_sym raised NoMethodError.
Convert through to_s first so such resources sort after the listed groups.
@eelcoj
eelcoj force-pushed the fix/adjacency-without-within branch from a82d4d7 to 19e15d7 Compare November 2, 2026 18:49
@eelcoj
eelcoj merged commit f555a4a into Rails-Designer:main Nov 2, 2026
0 of 3 checks passed
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.

2 participants