From 6a89efb9c9f79a5148965cb263e5a37ffa8afcc9 Mon Sep 17 00:00:00 2001 From: Guillem Arias Fauste Date: Thu, 4 Jun 2026 11:57:16 +0200 Subject: [PATCH] fix(goals): default goal currency so it survives a failed create (#2171) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a new goal failed server-side validation (e.g. no funding account selected), the currency was never assigned — `goal_params` doesn't permit `:currency` and it was only derived from the first linked account. On the re-rendered form the money field fell back to its USD default, so a CHF (or any non-USD) family saw their target amount silently reset to dollars, and a spurious "Currency must be filled" error appeared on a field the user can't even set. Always default the currency to the first linked account's currency when present, otherwise the family's primary currency. Currency is now never blank, so the derived-field error never surfaces and the money field keeps the family currency across a failed submit. Fixes we-promise/sure#2170 --- app/controllers/goals_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/goals_controller.rb b/app/controllers/goals_controller.rb index 7406f8fe4..1bb8f3c8a 100644 --- a/app/controllers/goals_controller.rb +++ b/app/controllers/goals_controller.rb @@ -61,7 +61,7 @@ class GoalsController < ApplicationController def create @goal = Current.family.goals.new(goal_params) accounts = lookup_accounts(params.dig(:goal, :account_ids)) - @goal.currency = accounts.first.currency if accounts.any? && @goal.currency.blank? + @goal.currency = (accounts.first&.currency || Current.family.primary_currency_code) if @goal.currency.blank? Goal.transaction do accounts.each { |a| @goal.goal_accounts.build(account: a) }