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">
<% 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 %>
</div>

View File

@@ -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