From 557ccd6164a0bade442ba256f755e4fdd4c422ee Mon Sep 17 00:00:00 2001 From: cryptogopher Date: Thu, 28 Nov 2019 21:00:14 +0100 Subject: [PATCH] Added update action --- app/controllers/quantities_controller.rb | 8 ++++++++ app/views/quantities/_index.html.erb | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/controllers/quantities_controller.rb b/app/controllers/quantities_controller.rb index 424a2ba..3a11fb4 100644 --- a/app/controllers/quantities_controller.rb +++ b/app/controllers/quantities_controller.rb @@ -39,6 +39,14 @@ class QuantitiesController < ApplicationController render :index end + def update + if @quantity.update(quantity_params) + flash[:notice] = 'Updated quantity' + end + prepare_quantities + render :index + end + def destroy if @quantity.destroy flash[:notice] = 'Deleted quantity' diff --git a/app/views/quantities/_index.html.erb b/app/views/quantities/_index.html.erb index 5920abc..f6134f1 100644 --- a/app/views/quantities/_index.html.erb +++ b/app/views/quantities/_index.html.erb @@ -61,7 +61,9 @@ <%= delete_link quantity_path(q), {remote: true, data: {}} %> - <% next unless (action_name == "edit") && (q == @quantity) %> + <% next unless (q == @quantity) && + ((action_name == "edit") || (action_name == "update" && @quantity.errors.present?)) + %>