Extract component for budget actions

We can omit passing a parameter to the helper method thanks to that, and
we group related code together.
This commit is contained in:
Javi Martín
2020-06-30 19:08:12 +02:00
parent 1537f25739
commit 02e27e13dc
5 changed files with 63 additions and 23 deletions

View File

@@ -0,0 +1,11 @@
<%= render Admin::TableActionsComponent.new(budget, actions: [:edit], edit_text: t("admin.budgets.index.edit_budget")) do %>
<%= link_to t("admin.budgets.index.budget_investments"),
admin_budget_budget_investments_path(budget_id: budget.id),
class: "button hollow medium" %>
<%= link_to t("admin.budgets.index.edit_groups"), admin_budget_groups_path(budget) %>
<% if budget.poll.present? %>
<%= link_to t("admin.budgets.index.admin_ballots"), admin_poll_booth_assignments_path(budget.poll) %>
<% else %>
<%= link_to_create_budget_poll %>
<% end %>
<% end %>

View File

@@ -0,0 +1,21 @@
class Admin::Budgets::TableActionsComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def link_to_create_budget_poll
balloting_phase = budget.phases.find_by(kind: "balloting")
link_to t("admin.budgets.index.admin_ballots"),
admin_polls_path(poll: {
name: budget.name,
budget_id: budget.id,
starts_at: balloting_phase.starts_at,
ends_at: balloting_phase.ends_at }),
method: :post
end
end