diff --git a/app/controllers/madmp_fragments_controller.rb b/app/controllers/madmp_fragments_controller.rb index 0760fea..9f75614 100644 --- a/app/controllers/madmp_fragments_controller.rb +++ b/app/controllers/madmp_fragments_controller.rb @@ -27,11 +27,13 @@ @fragment.assign_attributes(data: data) authorize @fragment - @fragment.answer.update!({ - lock_version: p_params[:answer][:lock_version], - is_common: p_params[:answer][:is_common], - user_id: current_user.id - }) + unless p_params[:source] == "modal" + @fragment.answer.update!({ + lock_version: p_params[:answer][:lock_version], + is_common: p_params[:answer][:is_common], + user_id: current_user.id + }) + end @fragment.save! rescue ActiveRecord::StaleObjectError @stale_fragment = @fragment @@ -53,15 +55,16 @@ }) @fragment.assign_attributes(data: data) - @fragment.answer = Answer.create!({ - research_output_id: p_params[:answer][:research_output_id], - plan_id: p_params[:answer][:plan_id], - plan_id: p_params[:answer][:plan_id], - question_id: p_params[:answer][:question_id], - lock_version: p_params[:answer][:lock_version], - is_common: p_params[:answer][:is_common], - user_id: current_user.id - }) + unless p_params[:source] == "modal" + @fragment.answer = Answer.create!({ + research_output_id: p_params[:answer][:research_output_id], + plan_id: p_params[:answer][:plan_id], + question_id: p_params[:answer][:question_id], + lock_version: p_params[:answer][:lock_version], + is_common: p_params[:answer][:is_common], + user_id: current_user.id + }) + end authorize @fragment @fragment.save! @@ -240,7 +243,7 @@ end def permitted_params - permit_arr = [:id, :dmp_id, :parent_id, :schema_id, + permit_arr = [:id, :dmp_id, :parent_id, :schema_id, :source, answer: [:id, :plan_id, :research_output_id, :question_id, :lock_version, :is_common] ] diff --git a/app/views/branded/madmp_fragments/_new_edit.html.erb b/app/views/branded/madmp_fragments/_new_edit.html.erb index cca176b..86eee12 100644 --- a/app/views/branded/madmp_fragments/_new_edit.html.erb +++ b/app/views/branded/madmp_fragments/_new_edit.html.erb @@ -5,7 +5,8 @@ <% q_format = question.question_format %> <% fragment_id = fragment.id unless fragment.nil? %> -<%= form_for :madmp_fragment, url: create_or_update_madmp_fragments_path(id: fragment_id), html: {method: :post, 'data-autosave': question.id, class: 'form-answer', id: nil } do |f| %> +<% url = fragment.present? ? create_or_update_madmp_fragments_path(id: fragment.id) : create_or_update_madmp_fragments_path %> +<%= form_for :madmp_fragment, url: url, html: {method: :post, 'data-autosave': question.id, class: 'form-answer', id: nil } do |f| %> <% if !readonly %> <%= f.fields_for(:answer, answer) do |af| %> <%= af.hidden_field :plan_id, id: nil %> @@ -19,6 +20,8 @@ <%= f.hidden_field :schema_id, :value => question.madmp_schema.id, id: nil %> <%= f.hidden_field :dmp_id, :value => dmp_id, id: nil %> <%= f.hidden_field :parent_id, :value => parent_id, id: nil %> + <%= f.hidden_field "source", :value => "form" %> +