1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-10 07:55:21 +02:00

Initialize rule with correct action for category CTA

This commit is contained in:
Zach Gollwitzer 2025-04-09 15:35:22 -04:00
parent ab912bbaa3
commit 757a1c019d
4 changed files with 10 additions and 6 deletions

View file

@ -15,8 +15,6 @@ class Account::TransactionsController < ApplicationController
category_id: transaction.category_id,
category_name: transaction.category.name
}
else
flash[:notice] = "Transaction updated"
end
respond_to do |format|

View file

@ -9,7 +9,13 @@ class RulesController < ApplicationController
end
def new
@rule = Current.family.rules.build(resource_type: params[:resource_type] || "transaction")
actions = []
if params[:action_type]
actions << Rule::Action.new(action_type: params[:action_type], value: params[:action_value])
end
@rule = Current.family.rules.build(resource_type: params[:resource_type] || "transaction", actions: actions)
end
def create

View file

@ -64,11 +64,11 @@ class Rule < ApplicationRecord
private
def min_conditions_and_actions
if conditions.reject(&:marked_for_destruction?).empty?
errors.add(:conditions, "must have at least one condition")
errors.add(:base, "must have at least one condition")
end
if actions.reject(&:marked_for_destruction?).empty?
errors.add(:actions, "must have at least one action")
errors.add(:base, "must have at least one action")
end
end

View file

@ -14,7 +14,7 @@
<%= tag.div class:"flex gap-2 justify-end" do %>
<%= f.submit "Dismiss", class: "btn btn--secondary" %>
<%= tag.a "Create rule", href: new_rule_path(resource_type: "transaction"), class: "btn btn--primary", data: { turbo_frame: "modal" } %>
<%= tag.a "Create rule", href: new_rule_path(resource_type: "transaction", action_type: "set_transaction_category", action_value: cta[:category_id]), class: "btn btn--primary", data: { turbo_frame: "modal" } %>
<% end %>
<% end %>
<% end %>