Add a controller method `redirect_back`

Akinori MUSHA 9 年之前
父节点
当前提交
00dcc88830
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      app/controllers/application_controller.rb

+ 6 - 0
app/controllers/application_controller.rb

@@ -6,6 +6,12 @@ class ApplicationController < ActionController::Base
6 6
 
7 7
   helper :all
8 8
 
9
+  def redirect_back(fallback_path, *args)
10
+    redirect_to :back, *args
11
+  rescue ActionController::RedirectBackError
12
+    redirect_to fallback_path, *args
13
+  end
14
+
9 15
   protected
10 16
 
11 17
   def configure_permitted_parameters