If there is a validation error, save action will redirect to the last known good location and set error message in a flash
This commit is contained in:
parent
5c8b738238
commit
73552b36a0
3 changed files with 54 additions and 19 deletions
|
@ -7,6 +7,8 @@ class ApplicationController < ActionController::Base
|
|||
# implements Instiki's legacy URLs
|
||||
require 'url_rewriting_hack'
|
||||
|
||||
after_filter :remember_location
|
||||
|
||||
# For injecting a different wiki model implementation. Intended for use in tests
|
||||
def self.wiki=(the_wiki)
|
||||
# a global variable is used here because Rails reloads controller and model classes in the
|
||||
|
@ -15,13 +17,37 @@ class ApplicationController < ActionController::Base
|
|||
$instiki_wiki_service = the_wiki
|
||||
logger.debug("Wiki service: #{the_wiki.to_s}")
|
||||
end
|
||||
|
||||
|
||||
def self.wiki
|
||||
$instiki_wiki_service
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def wiki
|
||||
$instiki_wiki_service
|
||||
end
|
||||
|
||||
@@REMEMBER_NOT = []
|
||||
|
||||
def remember_location
|
||||
if @response.headers['Status'] == '200 OK'
|
||||
@session[:return_to] = url_for unless @@REMEMBER_NOT.include? action_name
|
||||
@session[:already_tried_index_as_fallback] = false
|
||||
end
|
||||
end
|
||||
|
||||
def return_to_last_remembered
|
||||
# Forget the redirect location
|
||||
redirect_target, @session[:return_to] = @session[:return_to], nil
|
||||
# then try to redirect to it
|
||||
if redirect_target.nil?
|
||||
raise 'Cannot redirect to index' if @session[:already_tried_index_as_fallback]
|
||||
@session[:already_tried_index_as_fallback] = true
|
||||
redirect_to_url '/'
|
||||
else
|
||||
redirect_to_url(redirect_target)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue