From 7f2275c40ef4781f09919bd4d6628da78ebb997d Mon Sep 17 00:00:00 2001 From: Jez Caudle Date: Mon, 14 Oct 2024 11:55:43 +0100 Subject: [PATCH] Don't know how to get the page to scroll back to the last update Evidence is now saved More cleaning up to do. --- app/controllers/subprincipleitems_controller.rb | 9 +++++++-- app/views/cafs/_caf.html.erb | 7 ++++++- app/views/subprincipleitems/edit.html.erb | 5 +++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/subprincipleitems_controller.rb b/app/controllers/subprincipleitems_controller.rb index aa12d91..4da584f 100644 --- a/app/controllers/subprincipleitems_controller.rb +++ b/app/controllers/subprincipleitems_controller.rb @@ -1,5 +1,6 @@ class SubprincipleitemsController < ApplicationController before_action :set_subprincipleitem, only: %i[ edit update ] + before_action :set_caf, only: %i[ edit update ] def edit end @@ -7,7 +8,7 @@ class SubprincipleitemsController < ApplicationController def update respond_to do |format| if @subprincipleitem.update(subprincipleitem_params) - format.html { redirect_to company_url(@company), notice: "Company was successfully updated." } + format.html { redirect_to (company_caf_path(@caf.company, @caf) + "#subprincipleitem_#{@subprincipleitem.id}"), notice: "CAF item was updated." } format.json { render :show, status: :ok, location: @company } else format.html { render :edit, status: :unprocessable_entity } @@ -21,8 +22,12 @@ class SubprincipleitemsController < ApplicationController @subprincipleitem = Subprincipleitem.find(params[:id]) end + def set_caf + @caf = Caf.find(params[:caf_id]) + end + # Only allow a list of trusted parameters through. def subprincipleitem_params - params.require(:subprincipleitem).permit(:affirmative) + params.require(:subprincipleitem).permit(:affirmative,:evidence) end end diff --git a/app/views/cafs/_caf.html.erb b/app/views/cafs/_caf.html.erb index 906ab3f..c987ff2 100644 --- a/app/views/cafs/_caf.html.erb +++ b/app/views/cafs/_caf.html.erb @@ -27,7 +27,12 @@ <% subprinciple.subprincipleitemgroups.each do |subprincipleitemgroup| %> <% subprincipleitemgroup.subprincipleitems.each do |subprincipleitem| %> -
" class="subprincipleitem"><%= subprincipleitem.description %><%= link_to "Change", edit_caf_subprincipleitem_path(subprincipleitem) %> +
+ <%= subprincipleitem.description %> +
+ <%= link_to "Change", edit_caf_subprincipleitem_path(@caf,subprincipleitem) %> +
+
<% end %> diff --git a/app/views/subprincipleitems/edit.html.erb b/app/views/subprincipleitems/edit.html.erb index cd6c7cb..7cf454d 100644 --- a/app/views/subprincipleitems/edit.html.erb +++ b/app/views/subprincipleitems/edit.html.erb @@ -3,7 +3,8 @@

<%= @subprincipleitem.description %>

-<%= form_with(model: @subprincipleitem) do |form| %> +<%#= form_for( [company, caf] ) do |form| %> +<%= form_for( [ @caf, @subprincipleitem] ) do |form| %>

<%= form.label :affirmative %> <%= form.check_box :affirmative, {}, true, false %>
@@ -12,6 +13,6 @@ <%= form.rich_text_area :evidence %>
- <%= form.submit %> + <%= form.submit 'Update' %>
<% end %>