Redirect to a suitable page when HTML response requested for create/update.
authorTom Clegg <tom@clinicalfuture.com>
Thu, 26 Dec 2013 17:14:43 +0000 (09:14 -0800)
committerTom Clegg <tom@clinicalfuture.com>
Thu, 26 Dec 2013 17:14:43 +0000 (09:14 -0800)
apps/workbench/app/controllers/application_controller.rb

index 126dbbe14e38dad895e0cca308b9e57670d30ef0..57ba0cf7a1879413cab628d6e5206fc14d6268c5 100644 (file)
@@ -62,7 +62,13 @@ class ApplicationController < ActionController::Base
     end
     respond_to do |f|
       f.json { render json: @object }
-      f.html { render }
+      f.html {
+        if request.method == 'GET'
+          render
+        else
+          redirect_to params[:return_to] || @object
+        end
+      }
     end
   end
 
@@ -93,7 +99,7 @@ class ApplicationController < ActionController::Base
   def create
     @object ||= model_class.new params[model_class.to_s.singularize.to_sym]
     @object.save!
-    redirect_to @object
+    redirect_to(params[:return_to] || @object)
   end
 
   def destroy