feat(rules): create rule directly from transaction detail view
GF
15d ago+209+209+012345678901234567890123456789-2-2-0123456789
Summary
- Adds a "Create rule" action to the transaction detail drawer's Settings section, between "Mark as Recurring" and "Delete" — closes #2960.
- Reuses the existing
RulesController#newquery-param prefill (name→transaction_name/likecondition); no new controller logic. The link uses the transaction's merchant name if set, otherwise the transaction/payee name. - Deliberately minimal prefill: no action is pre-selected, the rule is not auto-applied. The user reviews/edits everything in the existing rule editor modal, then goes through the existing confirm/apply flow to (optionally) run it against history — consistent with how every other rule is created today.
Test plan
-
bin/rails test test/controllers/transactions_controller_test.rb— 4 new tests: merchant-name prefill, name fallback without a merchant, hidden for split-child transactions, hidden without edit permission on a shared read-only account. -
bin/rails test test/models/rule_test.rb test/controllers/rules_controller_test.rb test/i18n_test.rb— no regressions (existingRulesController#newprefill path is unchanged). -
bin/rubocop -f github -a— clean. -
bundle exec erb_lint -aon the touched views — clean. -
bin/brakeman --no-pager— 0 warnings. - Manually verified in a running instance: opened a transaction, "Create rule" appears between "Mark as Recurring" and "Delete", opens the rule editor modal with the name condition pre-filled from the transaction's merchant.
🤖 Generated with Claude Code
Summary by CodeRabbit
-
New Features
- Added a Create Rule option to the transaction details drawer.
- Rule creation is prefilled using the transaction’s merchant when available, or its name otherwise.
- The option is available for editable transactions and hidden for split child transactions or when editing isn’t permitted.
- The create-rule link refreshes after transaction updates, including validation failures, to reflect current details.
-
Bug Fixes
- Invalid merchant identifiers now safely fall back to name-based rule creation.
-
Tests
- Added coverage for prefilling, link updates, fallback behavior, and visibility rules.