The personal finance app for everyone
Add error handling for vehicle and property account creation (#1179)
Tony Vincente06f0c76f958
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rbindex db54d17c..11b55ac6 100644--- a/app/controllers/accounts_controller.rb+++ b/app/controllers/accounts_controller.rb@@ -58,8 +58,6 @@ class AccountsController < ApplicationControllerstart_balance: account_params[:start_balance]@account.sync_laterredirect_back_or_to account_path(@account), notice: t(".success")- rescue ActiveRecord::RecordInvalid => e- redirect_back_or_to accounts_path, alert: e.record.errors.full_messages.to_sentenceenddef destroydiff --git a/app/helpers/forms_helper.rb b/app/helpers/forms_helper.rbindex 19f75b29..c5d3d5d5 100644--- a/app/helpers/forms_helper.rb+++ b/app/helpers/forms_helper.rb@@ -34,7 +34,8 @@ module FormsHelperdefault_currency: options[:default_currency] || "USD",disable_currency: options[:disable_currency] || false,hide_currency: options[:hide_currency] || false,- label: options[:label] || "Amount"+ label: options[:label] || "Amount",+ required: options[:required] || false}enddiff --git a/app/views/accounts/_form.html.erb b/app/views/accounts/_form.html.erbindex 86ee96bd..ad537264 100644--- a/app/views/accounts/_form.html.erb+++ b/app/views/accounts/_form.html.erb@@ -5,7 +5,7 @@<%= f.hidden_field :accountable_type %><%= f.text_field :name, placeholder: t(".name_placeholder"), required: "required", label: t(".name_label"), autofocus: true %><%= f.collection_select :institution_id, Current.family.institutions.alphabetically, :id, :name, { include_blank: t(".ungrouped"), label: t(".institution") } %>- <%= money_with_currency_field f, :balance_money, label: t(".balance"), required: "required", default_currency: Current.family.currency %>+ <%= money_with_currency_field f, :balance_money, label: t(".balance"), required: true, default_currency: Current.family.currency %><% if account.new_record? %><div class="flex items-center gap-2 mt-3 mb-6">diff --git a/app/views/shared/_money_field.html.erb b/app/views/shared/_money_field.html.erbindex 14fe7e7b..ae863ff0 100644--- a/app/views/shared/_money_field.html.erb+++ b/app/views/shared/_money_field.html.erb@@ -1,4 +1,4 @@-<%# locals: (form:, money_method:, default_currency:, disable_currency: false, hide_currency: false, label: nil) %>+<%# locals: (form:, money_method:, default_currency:, disable_currency: false, hide_currency: false, label: nil, required: false) %><% fallback_label = t(".money-label") %><% currency = form.object ? (form.object.send(money_method)&.currency || Money::Currency.new(default_currency)) : Money::Currency.new(default_currency) %>@@ -9,7 +9,7 @@<div class="flex items-center gap-1"><div class="flex items-center grow gap-1"><span class="text-gray-500 text-sm" data-money-field-target="symbol"><%= currency.symbol %></span>- <%= money_field form, money_method, { inline: true, "data-money-field-target" => "amount", default_currency: currency } %>+ <%= money_field form, money_method, { inline: true, "data-money-field-target" => "amount", default_currency: currency, required: required } %></div><% unless hide_currency %><div>