Module: SimpleWorkflow::Controller
- Included in:
- ActionController::Base
- Defined in:
- lib/simple_workflow/controller.rb
Instance Method Summary collapse
- #back ⇒ Object
- #back_or_redirect_to(options) ⇒ Object
- #detour_to(options) ⇒ Object
- #pop_detour ⇒ Object
- #redirect_to_post(options) ⇒ Object
- #rjs_detour_to(options) ⇒ Object
- #rjs_redirect_to(options) ⇒ Object
- #store_detour(options, post = false) ⇒ Object
- #store_detour_from_params ⇒ Object
Instance Method Details
#back ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/simple_workflow/controller.rb', line 37 def back return false if session[:detours].nil? detour = pop_detour post = detour.delete(:request_method) == :post if post redirect_to_post(detour) else redirect_to detour end return true end |
#back_or_redirect_to(options) ⇒ Object
49 50 51 |
# File 'lib/simple_workflow/controller.rb', line 49 def back_or_redirect_to() back or redirect_to end |
#detour_to(options) ⇒ Object
2 3 4 5 |
# File 'lib/simple_workflow/controller.rb', line 2 def detour_to() store_detour(params) redirect_to() end |
#pop_detour ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/simple_workflow/controller.rb', line 53 def pop_detour detours = session[:detours] return nil unless detours detour = detours.pop logger.debug "popped detour: #{detour.inspect} #{session[:detours].size} more" if detours.empty? session[:detours] = nil end detour end |
#redirect_to_post(options) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/simple_workflow/controller.rb', line 64 def redirect_to_post() url = url_for render :text => <<EOF, :layout => false <html> <body onload="document.getElementById('form').submit()"> <form id="form" action="#{url}" method="POST"> </form> </body> </html> EOF end |
#rjs_detour_to(options) ⇒ Object
7 8 9 10 |
# File 'lib/simple_workflow/controller.rb', line 7 def rjs_detour_to() store_detour(params, request.post?) rjs_redirect_to() end |
#rjs_redirect_to(options) ⇒ Object
12 13 14 15 |
# File 'lib/simple_workflow/controller.rb', line 12 def rjs_redirect_to() @options = render :template => 'redirect', :layout => false end |
#store_detour(options, post = false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/simple_workflow/controller.rb', line 17 def store_detour(, post = false) [:request_method] = :post if post if session[:detours] && session[:detours].last == logger.debug "duplicate detour: #{.inspect}" return end logger.debug "adding detour: #{.inspect}" session[:detours] ||= [] session[:detours] << end |
#store_detour_from_params ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/simple_workflow/controller.rb', line 28 def store_detour_from_params if params[:detour] store_detour(params[:detour]) end if params[:return_from_detour] && session[:detours] pop_detour end end |