Extract commponent to render user investment actions

This way it'll be easier to organize code related to it.
This commit is contained in:
Javi Martín
2024-10-11 16:15:34 +02:00
parent 58cba2316a
commit 0e2434c094
3 changed files with 18 additions and 9 deletions

View File

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

View File

@@ -0,0 +1,8 @@
class Users::BudgetInvestmentTableActionsComponent < ApplicationComponent
attr_reader :investment
use_helpers :can?
def initialize(investment)
@investment = investment
end
end

View File

@@ -3,14 +3,6 @@
<%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %> <%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %>
</td> </td>
<td> <td>
<% if can? :update, budget_investment %> <%= render Users::BudgetInvestmentTableActionsComponent.new(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 %>
</td> </td>
</tr> </tr>