Extract method to get toggle selection path

This way we simplify the view code.

Since now we only use the `budget` method in one place, we're removing
it.
This commit is contained in:
Javi Martín
2021-08-21 00:29:07 +02:00
parent fde24870bc
commit c78494c100
2 changed files with 13 additions and 22 deletions

View File

@@ -1,32 +1,14 @@
<% if investment.selected? %> <% if investment.selected? %>
<%= link_to_if can?(:toggle_selection, investment), <%= link_to_if can?(:toggle_selection, investment),
t("admin.budget_investments.index.selected"), t("admin.budget_investments.index.selected"),
toggle_selection_admin_budget_budget_investment_path( path,
budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]
),
method: :patch, method: :patch,
remote: true, remote: true,
class: "button small expanded" %> class: "button small expanded" %>
<% elsif investment.feasible? && investment.valuation_finished? %> <% elsif investment.feasible? && investment.valuation_finished? %>
<% if can?(:toggle_selection, investment) %> <% if can?(:toggle_selection, investment) %>
<%= link_to t("admin.budget_investments.index.select"), <%= link_to t("admin.budget_investments.index.select"),
toggle_selection_admin_budget_budget_investment_path( path,
budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]
),
method: :patch, method: :patch,
remote: true, remote: true,
class: "button small hollow expanded" %> class: "button small hollow expanded" %>

View File

@@ -8,7 +8,16 @@ class Admin::BudgetInvestments::ToggleSelectionComponent < ApplicationComponent
private private
def budget def path
investment.budget toggle_selection_admin_budget_budget_investment_path(
investment.budget,
investment,
filter: params[:filter],
sort_by: params[:sort_by],
min_total_supports: params[:min_total_supports],
max_total_supports: params[:max_total_supports],
advanced_filters: params[:advanced_filters],
page: params[:page]
)
end end
end end