diff --git a/app/components/budgets/investments/form_component.html.erb b/app/components/budgets/investments/form_component.html.erb
new file mode 100644
index 000000000..73730f718
--- /dev/null
+++ b/app/components/budgets/investments/form_component.html.erb
@@ -0,0 +1,107 @@
+<%= translatable_form_for(investment, url: url, html: { multipart: true }) do |f| %>
+
+ <%= render "shared/errors", resource: investment %>
+
+
+ <% unless budget.single_heading? %>
+
+ <%= f.select :heading_id, budget_heading_select_options(budget), { include_blank: true } %>
+
+ <% end %>
+
+
+
+ <%= render "shared/globalize_locales", resource: investment %>
+
+
+
+ <%= f.translatable_fields do |translations_form| %>
+
+ <%= translations_form.text_field :title,
+ maxlength: Budget::Investment.title_max_length,
+ data: suggest_data(investment) %>
+
+
+
+
+ <%= translations_form.text_area :description,
+ maxlength: Budget::Investment.description_max_length,
+ class: "html-area" %>
+
+ <% end %>
+
+ <%= f.invisible_captcha :subtitle %>
+
+ <% if feature?(:allow_images) %>
+
+ <%= render "images/nested_image", imageable: investment, f: f %>
+
+ <% end %>
+
+ <% if feature?(:allow_attached_documents) %>
+
+ <%= render "documents/nested_documents", documentable: investment, f: f %>
+
+ <% end %>
+
+ <% if feature?(:map) %>
+
+ <%= render "map_locations/form_fields",
+ form: f,
+ map_location: investment.map_location || MapLocation.new,
+ label: t("budgets.investments.form.map_location"),
+ help: t("budgets.investments.form.map_location_instructions"),
+ remove_marker_label: t("budgets.investments.form.map_remove_marker"),
+ parent_class: "budget_investment",
+ i18n_namespace: "budgets.investments" %>
+
+ <% end %>
+
+
+ <%= f.text_field :location %>
+
+
+
+ <%= f.text_field :organization_name %>
+
+
+
+ <%= f.label :tag_list, t("budgets.investments.form.tags_label") %>
+
<%= t("budgets.investments.form.tags_instructions") %>
+
+
+
+
+ <%= f.text_field :tag_list, value: investment.tag_list.to_s,
+ label: false,
+ placeholder: t("budgets.investments.form.tags_placeholder"),
+ aria: { describedby: "tags-list-help-text" },
+ class: "js-tag-list tag-autocomplete",
+ data: { js_url: suggest_tags_path } %>
+
+
+ <%= render SDG::RelatedListSelectorComponent.new(f) %>
+
+ <% unless current_user.manager? %>
+
+
+ <%= f.check_box :terms_of_service,
+ title: t("form.accept_terms_title"),
+ label: t("form.accept_terms",
+ policy: link_to(t("form.policy"), "/privacy", target: "blank"),
+ conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
+ ) %>
+
+
+ <% end %>
+
+
+ <%= f.submit(nil, class: "button expanded") %>
+
+
+<% end %>
diff --git a/app/components/budgets/investments/form_component.rb b/app/components/budgets/investments/form_component.rb
new file mode 100644
index 000000000..181328e04
--- /dev/null
+++ b/app/components/budgets/investments/form_component.rb
@@ -0,0 +1,21 @@
+class Budgets::Investments::FormComponent < ApplicationComponent
+ include TranslatableFormHelper
+ include GlobalizeHelper
+ attr_reader :investment, :url
+ delegate :current_user, :budget_heading_select_options, :suggest_data, to: :helpers
+
+ def initialize(investment, url:)
+ @investment = investment
+ @url = url
+ end
+
+ private
+
+ def budget
+ investment.budget
+ end
+
+ def categories
+ Tag.category.order(:name)
+ end
+end
diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb
index 6286fe13b..a06e68d1e 100644
--- a/app/controllers/budgets/investments_controller.rb
+++ b/app/controllers/budgets/investments_controller.rb
@@ -22,7 +22,7 @@ module Budgets
before_action :load_ballot, only: [:index, :show]
before_action :load_heading, only: [:index, :show]
before_action :set_random_seed, only: :index
- before_action :load_categories, only: [:index, :new, :create, :edit, :update]
+ before_action :load_categories, only: :index
before_action :set_default_investment_filter, only: :index
before_action :set_view, only: :index
before_action :load_content_blocks, only: :index
diff --git a/app/controllers/management/budgets/investments_controller.rb b/app/controllers/management/budgets/investments_controller.rb
index 627964a69..ae3abf85d 100644
--- a/app/controllers/management/budgets/investments_controller.rb
+++ b/app/controllers/management/budgets/investments_controller.rb
@@ -18,7 +18,6 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end
def new
- load_categories
end
def create
@@ -30,7 +29,6 @@ class Management::Budgets::InvestmentsController < Management::BaseController
notice = t("flash.actions.create.notice", resource_name: Budget::Investment.model_name.human, count: 1)
redirect_to management_budget_investment_path(@budget, @investment), notice: notice
else
- load_categories
render :new
end
end
@@ -59,8 +57,4 @@ class Management::Budgets::InvestmentsController < Management::BaseController
def load_budget
@budget = Budget.find_by_slug_or_id! params[:budget_id]
end
-
- def load_categories
- @categories = Tag.category.order(:name)
- end
end
diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb
index 8296a2e30..4ef77fb0d 100644
--- a/app/views/budgets/investments/_form.html.erb
+++ b/app/views/budgets/investments/_form.html.erb
@@ -1,109 +1 @@
-<%= translatable_form_for(@investment, url: form_url, html: { multipart: true }) do |f| %>
-
- <%= render "shared/errors", resource: @investment %>
-
-
- <% unless @budget.single_heading? %>
-
- <%= f.select :heading_id, budget_heading_select_options(@budget), { include_blank: true } %>
-
- <% end %>
-
-
-
- <%= render "shared/globalize_locales", resource: @investment %>
-
-
-
- <%= f.translatable_fields do |translations_form| %>
-
- <%= translations_form.text_field :title,
- maxlength: Budget::Investment.title_max_length,
- data: suggest_data(@investment) %>
-
-
-
-
- <%= translations_form.text_area :description,
- maxlength: Budget::Investment.description_max_length,
- class: "html-area" %>
-
- <% end %>
-
- <%= f.invisible_captcha :subtitle %>
-
- <% if feature?(:allow_images) %>
-
- <%= render "images/nested_image", imageable: @investment, f: f %>
-
- <% end %>
-
- <% if feature?(:allow_attached_documents) %>
-
- <%= render "documents/nested_documents", documentable: @investment, f: f %>
-
- <% end %>
-
- <% if feature?(:map) %>
-
-
- <%= render "map_locations/form_fields",
- form: f,
- map_location: @investment.map_location || MapLocation.new,
- label: t("budgets.investments.form.map_location"),
- help: t("budgets.investments.form.map_location_instructions"),
- remove_marker_label: t("budgets.investments.form.map_remove_marker"),
- parent_class: "budget_investment",
- i18n_namespace: "budgets.investments" %>
-
-
- <% end %>
-
-
- <%= f.text_field :location %>
-
-
-
- <%= f.text_field :organization_name %>
-
-
-
- <%= f.label :tag_list, t("budgets.investments.form.tags_label") %>
-
<%= t("budgets.investments.form.tags_instructions") %>
-
-
-
-
- <%= f.text_field :tag_list, value: @investment.tag_list.to_s,
- label: false,
- placeholder: t("budgets.investments.form.tags_placeholder"),
- aria: { describedby: "tags-list-help-text" },
- class: "js-tag-list tag-autocomplete",
- data: { js_url: suggest_tags_path } %>
-
-
- <%= render SDG::RelatedListSelectorComponent.new(f) %>
-
- <% unless current_user.manager? %>
-
-
- <%= f.check_box :terms_of_service,
- title: t("form.accept_terms_title"),
- label: t("form.accept_terms",
- policy: link_to(t("form.policy"), "/privacy", target: "blank"),
- conditions: link_to(t("form.conditions"), "/conditions", target: "blank")
- ) %>
-
-
- <% end %>
-
-
- <%= f.submit(nil, class: "button expanded") %>
-
-
-<% end %>
+<%= render Budgets::Investments::FormComponent.new(@investment, url: form_url) %>