Conversation
The priority select posted integer enum values as strings ("2"), which
Rails rejects as invalid keys. Submit enum names from the form, keep
integer values for the Ransack filter, and validate the enum so bad
priorities become form errors instead of a 500.
Co-authored-by: Thibaud Guillaume-Gentil <thibaud@thibaud.gg>
enum validate: true marks priority as required, and Rails then rejects include_blank: false on the select. The model still validates inclusion; the input stays a compact mark picker with a default of normal. Co-authored-by: Thibaud Guillaume-Gentil <thibaud@thibaud.gg>
Member
Author
|
Replaced by 5256a5e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Production AppSignal incident #733:
ArgumentError: '2' is not a valid priorityonSupportTicketsController#create(tenant ragedevert).The new support ticket form used
ticket_priority_marks_collection, which posted Rails enum integers (0/1/2). HTML always submits those as strings. Rails enums accept the integer2(high) or the name"high", but reject"2"as an unknown key and raise duringassign_attributes— a 500 instead of a form error.Selecting‼️ (high) on the live form is what triggered this.
Fix
normal/medium/high) from the create/edit priority select.enum :priority, …, validate: trueso unexpected values (including"2") become an inclusion error and re-render the form, instead of raising.required: falseon the select so Rails does not rejectinclude_blank: falsenow that the enum is validated. The model still rejects bad priorities; the picker keeps its default of normal.Tests
"2"does not raise; it fails inclusion validation."high"remains valid."high"creates the ticket; posting"2"returns 422 with a priority field error.Do not merge or deploy from this PR.