From cbdf2f7f220d27653eaf4bf578f63f66753e01ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 11 Oct 2024 16:44:25 +0200 Subject: [PATCH] Extract methods in user investment table actions --- ...t_investment_table_actions_component.html.erb | 8 +++----- .../budget_investment_table_actions_component.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/app/components/users/budget_investment_table_actions_component.html.erb b/app/components/users/budget_investment_table_actions_component.html.erb index ea9290bcd..a29abf847 100644 --- a/app/components/users/budget_investment_table_actions_component.html.erb +++ b/app/components/users/budget_investment_table_actions_component.html.erb @@ -1,11 +1,9 @@
<% if can? :update, investment %> - <%= link_to t("shared.edit"), edit_budget_investment_path(investment.budget, investment), - class: "button hollow" %> + <%= edit_link %> <% end %> + <% if can? :destroy, investment %> - <%= button_to t("shared.delete"), budget_investment_path(investment.budget, investment), - method: :delete, class: "button hollow alert", - data: { confirm: t("users.show.delete_alert") } %> + <%= destroy_button %> <% end %>
diff --git a/app/components/users/budget_investment_table_actions_component.rb b/app/components/users/budget_investment_table_actions_component.rb index 9628a4383..8a12a4e33 100644 --- a/app/components/users/budget_investment_table_actions_component.rb +++ b/app/components/users/budget_investment_table_actions_component.rb @@ -5,4 +5,20 @@ class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent def initialize(investment) @investment = investment end + + private + + def edit_link + link_to t("shared.edit"), + edit_budget_investment_path(investment.budget, investment), + class: "button hollow" + end + + def destroy_button + button_to t("shared.delete"), + budget_investment_path(investment.budget, investment), + method: :delete, + class: "button hollow alert", + data: { confirm: t("users.show.delete_alert") } + end end