/
render_redirect.rb
50 lines (41 loc) · 1.05 KB
/
render_redirect.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module Wicked::Controller::Concerns::RenderRedirect
extend ActiveSupport::Concern
def render_wizard(resource = nil, options = {})
process_resource!(resource)
if @skip_to
redirect_to wizard_path(@skip_to), options
else
render_step wizard_value(step), options
end
end
def process_resource!(resource)
if resource
if resource.save
@skip_to ||= @next_step
else
@skip_to = nil
end
end
end
def render_step(the_step, options = {})
if the_step.nil? || the_step.to_s == Wicked::FINISH_STEP
redirect_to_finish_wizard options
else
render ERB::Util.url_encode(the_step), options
end
end
def redirect_to_next(next_step, options = {})
if next_step.nil?
redirect_to_finish_wizard(options)
else
redirect_to wizard_path(next_step), options
end
end
# TODO redirect to resource if one is passed to render_wizard
def finish_wizard_path
'/'
end
def redirect_to_finish_wizard(options = {})
redirect_to finish_wizard_path, options
end
end