Module: SimpleWorkflow::Controller
- Includes:
- Detour
- Defined in:
- lib/simple_workflow/controller.rb
Overview
Mixin to add controller methods for workflow navigation.
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/simple_workflow/controller.rb', line 30
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
45
46
47
|
# File 'lib/simple_workflow/controller.rb', line 45
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.
9
10
11
12
|
# File 'lib/simple_workflow/controller.rb', line 9
def detour_to(options)
store_detour(params)
redirect_to(options)
end
|
#redirect_to_post(options) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/simple_workflow/controller.rb', line 63
def redirect_to_post(options)
url = url_for options
render text: <<EOF.strip_heredoc, 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
14
15
16
17
|
# File 'lib/simple_workflow/controller.rb', line 14
def rjs_detour_to(options)
store_detour(params, request.post?)
rjs_redirect_to(options)
end
|
#rjs_redirect_to(options) ⇒ Object
19
20
21
22
|
# File 'lib/simple_workflow/controller.rb', line 19
def rjs_redirect_to(options)
@options = options
render template: 'redirect', layout: false, formats: :js
end
|
#store_detour(options, post = false) ⇒ Object
24
25
26
27
28
|
# File 'lib/simple_workflow/controller.rb', line 24
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
|