Fix NoMethodError for us_postage_type on Letter::Batch instances #157
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.
The
Letter::BatchesController#validate_postage_typesmethod was failing with aNoMethodError: undefined method 'us_postage_type' for an instance of Letter::Batchwhen trying to validate postage types during batch updates.Root Cause
The controller's
validate_postage_typesmethod attempts to access@batch.us_postage_typeand@batch.intl_postage_type:However, these attributes don't exist on the
Letter::Batchmodel - they are form parameters used for processing but not persisted to the database.Solution
Added
us_postage_typeandintl_postage_typeas virtual attributes usingattr_accessorin theLetter::Batchmodel:This allows the form parameters to be set on the batch instance during updates and accessed during validation, without requiring database columns. The approach follows existing patterns in the codebase (e.g.,
from_letterattribute inReturnAddressmodel).Testing
Verified the fix handles all scenarios correctly:
Fixes #156.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.