Extract methods in user investment table actions

This commit is contained in:
Javi Martín
2024-10-11 16:44:25 +02:00
parent b694ee7077
commit cbdf2f7f22
2 changed files with 19 additions and 5 deletions

View File

@@ -1,11 +1,9 @@
<div class="user-budget-investment-table-actions"> <div class="user-budget-investment-table-actions">
<% if can? :update, investment %> <% if can? :update, investment %>
<%= link_to t("shared.edit"), edit_budget_investment_path(investment.budget, investment), <%= edit_link %>
class: "button hollow" %>
<% end %> <% end %>
<% if can? :destroy, investment %> <% if can? :destroy, investment %>
<%= button_to t("shared.delete"), budget_investment_path(investment.budget, investment), <%= destroy_button %>
method: :delete, class: "button hollow alert",
data: { confirm: t("users.show.delete_alert") } %>
<% end %> <% end %>
</div> </div>

View File

@@ -5,4 +5,20 @@ class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent
def initialize(investment) def initialize(investment)
@investment = investment @investment = investment
end 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 end