From 0e2434c0945082f797a10410655e7e51366a6493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 11 Oct 2024 16:15:34 +0200 Subject: [PATCH] Extract commponent to render user investment actions This way it'll be easier to organize code related to it. --- .../budget_investment_table_actions_component.html.erb | 9 +++++++++ .../users/budget_investment_table_actions_component.rb | 8 ++++++++ app/views/users/_budget_investment.html.erb | 10 +--------- 3 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 app/components/users/budget_investment_table_actions_component.html.erb create mode 100644 app/components/users/budget_investment_table_actions_component.rb diff --git a/app/components/users/budget_investment_table_actions_component.html.erb b/app/components/users/budget_investment_table_actions_component.html.erb new file mode 100644 index 000000000..45674e2b2 --- /dev/null +++ b/app/components/users/budget_investment_table_actions_component.html.erb @@ -0,0 +1,9 @@ +<% if can? :update, investment %> + <%= link_to t("shared.edit"), edit_budget_investment_path(investment.budget, investment), + class: "button hollow" %> +<% end %> +<% if can? :destroy, investment %> + <%= link_to t("shared.delete"), budget_investment_path(investment.budget, investment), + method: :delete, class: "button hollow alert", + data: { confirm: t("users.show.delete_alert") } %> +<% end %> diff --git a/app/components/users/budget_investment_table_actions_component.rb b/app/components/users/budget_investment_table_actions_component.rb new file mode 100644 index 000000000..9628a4383 --- /dev/null +++ b/app/components/users/budget_investment_table_actions_component.rb @@ -0,0 +1,8 @@ +class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent + attr_reader :investment + use_helpers :can? + + def initialize(investment) + @investment = investment + end +end diff --git a/app/views/users/_budget_investment.html.erb b/app/views/users/_budget_investment.html.erb index 7c9dc0fec..81377519c 100644 --- a/app/views/users/_budget_investment.html.erb +++ b/app/views/users/_budget_investment.html.erb @@ -3,14 +3,6 @@ <%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %> - <% if can? :update, budget_investment %> - <%= link_to t("shared.edit"), edit_budget_investment_path(budget_investment.budget, budget_investment), - class: "button hollow" %> - <% end %> - <% if can? :destroy, budget_investment %> - <%= link_to t("shared.delete"), budget_investment_path(budget_investment.budget, budget_investment), - method: :delete, class: "button hollow alert", - data: { confirm: t("users.show.delete_alert") } %> - <% end %> + <%= render Users::BudgetInvestmentTableActionsComponent.new(budget_investment) %>