Module: SimpleWorkflow::Controller
Instance Method Summary
collapse
Methods included from Detour
#pop_detour, #reset_workflow, #store_detour_in_session
Instance Method Details
#back(response_status_and_flash) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/simple_workflow/controller.rb', line 28
def back(response_status_and_flash)
return false if session[:detours].nil?
detour = pop_detour(session)
post = detour.delete(:request_method) == :post
if post
save_flash(response_status_and_flash)
redirect_to_post(detour)
else
redirect_to detour, response_status_and_flash
end
true
rescue
retry
end
|
#back_or_redirect_to(options = {}, response_status_and_flash = {}) ⇒ Object
43
44
45
|
# File 'lib/simple_workflow/controller.rb', line 43
def back_or_redirect_to(options = {}, response_status_and_flash = {})
back(response_status_and_flash) || redirect_to(options, response_status_and_flash)
end
|
#detour_to(options) ⇒ Object
Like ActionController::Base#redirect_to, but stores the location we come from, enabling returning here later.
7
8
9
10
|
# File 'lib/simple_workflow/controller.rb', line 7
def detour_to(options)
store_detour(params)
redirect_to(options)
end
|
#redirect_to_post(options) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/simple_workflow/controller.rb', line 61
def redirect_to_post(options)
url = url_for options
render text: " <html>\n <body onload=\"document.getElementById('form').submit()\">\n <form id=\"form\" action=\"\#{url}\" method=\"POST\">\n </form>\n </body>\n </html>\n".strip_heredoc, layout: false
end
|
#rjs_detour_to(options) ⇒ Object
12
13
14
15
|
# File 'lib/simple_workflow/controller.rb', line 12
def rjs_detour_to(options)
store_detour(params, request.post?)
rjs_redirect_to(options)
end
|
#rjs_redirect_to(options) ⇒ Object
17
18
19
20
|
# File 'lib/simple_workflow/controller.rb', line 17
def rjs_redirect_to(options)
@options = options
render template: 'redirect', layout: false, formats: :js
end
|
#store_detour(options, post = false) ⇒ Object
22
23
24
25
26
|
# File 'lib/simple_workflow/controller.rb', line 22
def store_detour(options, post = false)
options = options.dup.permit!.to_h if options.is_a?(ActionController::Parameters)
options[:request_method] = :post if post
store_detour_in_session(session, options)
end
|