diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb index 2170caa50..799d1f76d 100644 --- a/app/controllers/budgets/investments_controller.rb +++ b/app/controllers/budgets/investments_controller.rb @@ -49,6 +49,7 @@ module Budgets def create @investment.author = current_user + recover_documents_from_cache(@investment) if @investment.save Mailer.budget_investment_created(@investment).deliver_later @@ -105,7 +106,8 @@ module Budgets def investment_params params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id, :tag_list, - :organization_name, :location, :terms_of_service) + :organization_name, :location, :terms_of_service, + documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id]) end def load_ballot diff --git a/app/helpers/documents_helper.rb b/app/helpers/documents_helper.rb index ec2541aaa..819d4a00f 100644 --- a/app/helpers/documents_helper.rb +++ b/app/helpers/documents_helper.rb @@ -23,13 +23,13 @@ module DocumentsHelper end def document_nested_field_name(document, index, field) - parent = document.documentable_type.constantize.name.downcase - "#{parent}[documents_attributes][#{index}][#{field}]" + parent = document.documentable_type.parameterize.underscore + "#{parent.parameterize}[documents_attributes][#{index}][#{field}]" end def document_nested_field_id(document, index, field) - parent = document.documentable_type.constantize.name.downcase - "#{parent}_documents_attributes_#{index}_#{field}" + parent = document.documentable_type.parameterize.underscore + "#{parent.parameterize}_documents_attributes_#{index}_#{field}" end def document_nested_field_wrapper_id(index) diff --git a/app/models/budget/investment.rb b/app/models/budget/investment.rb index 1fb0c1b26..0dfd7836c 100644 --- a/app/models/budget/investment.rb +++ b/app/models/budget/investment.rb @@ -10,6 +10,7 @@ class Budget documentable max_documents_allowed: 3, max_file_size: 3.megabytes, accepted_content_types: [ "application/pdf" ] + accepts_nested_attributes_for :documents, allow_destroy: true acts_as_votable acts_as_paranoid column: :hidden_at diff --git a/app/views/budgets/investments/_form.html.erb b/app/views/budgets/investments/_form.html.erb index 94f6283e9..40685dff7 100644 --- a/app/views/budgets/investments/_form.html.erb +++ b/app/views/budgets/investments/_form.html.erb @@ -21,6 +21,10 @@ <%= f.text_field :external_url %> +