wicked 1.0.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/check_changelog.yml +13 -0
- data/.github/workflows/ci.yml +53 -0
- data/.gitignore +15 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +45 -0
- data/CONTRIBUTING.md +19 -0
- data/Gemfile +3 -20
- data/README.md +150 -35
- data/Rakefile +2 -15
- data/gemfiles/rails_5.2.gemfile +12 -0
- data/gemfiles/rails_6.0.gemfile +12 -0
- data/gemfiles/rails_7.0.gemfile +12 -0
- data/lib/wicked/controller/concerns/action.rb +13 -0
- data/lib/wicked/controller/concerns/path.rb +13 -3
- data/lib/wicked/controller/concerns/render_redirect.rb +35 -23
- data/lib/wicked/controller/concerns/steps.rb +12 -17
- data/lib/wicked/version.rb +3 -0
- data/lib/wicked/wizard/translated.rb +3 -6
- data/lib/wicked/wizard.rb +28 -23
- data/{app/controllers → lib}/wicked/wizard_controller.rb +1 -2
- data/lib/wicked.rb +2 -1
- data/test/controllers/bar_controller_test.rb +3 -2
- data/test/controllers/status_codes_controller_test.rb +18 -0
- data/test/controllers/updates_controller_test.rb +27 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -2
- data/test/dummy/app/controllers/dynamic_different_steps_controller.rb +18 -0
- data/test/dummy/app/controllers/dynamic_steps_controller.rb +1 -1
- data/test/dummy/app/controllers/jump_controller.rb +9 -2
- data/test/dummy/app/controllers/redirect_to_next_controller.rb +1 -1
- data/test/dummy/app/controllers/status_codes_controller.rb +39 -0
- data/test/dummy/app/controllers/update_params_controller.rb +30 -0
- data/test/dummy/app/controllers/updates_controller.rb +30 -0
- data/test/dummy/app/views/bar/first.html.erb +3 -1
- data/test/dummy/app/views/bar/second.html.erb +2 -1
- data/test/dummy/app/views/dynamic_different_steps/first.html.erb +3 -0
- data/test/dummy/app/views/jump/last_step.html.erb +3 -1
- data/test/dummy/app/views/jump/second.html.erb +3 -1
- data/test/dummy/app/views/status_codes/bad.html.erb +1 -0
- data/test/dummy/app/views/status_codes/good.html.erb +1 -0
- data/test/dummy/app/views/update_params/_step_position.html.erb +16 -0
- data/test/dummy/app/views/update_params/first.html.erb +1 -0
- data/test/dummy/app/views/update_params/index.html.erb +1 -0
- data/test/dummy/app/views/update_params/last_step.html.erb +1 -0
- data/test/dummy/app/views/update_params/second.html.erb +1 -0
- data/test/dummy/app/views/updates/_step_position.html.erb +16 -0
- data/test/dummy/app/views/updates/first.html.erb +1 -0
- data/test/dummy/app/views/updates/index.html.erb +1 -0
- data/test/dummy/app/views/updates/last_step.html.erb +1 -0
- data/test/dummy/app/views/updates/second.html.erb +1 -0
- data/test/dummy/config/application.rb +3 -0
- data/test/dummy/config/environments/development.rb +0 -1
- data/test/dummy/config/environments/test.rb +3 -1
- data/test/dummy/config/routes.rb +4 -0
- data/test/integration/dynamic_steps_test.rb +8 -1
- data/test/integration/helpers_test.rb +27 -0
- data/test/integration/jump_test.rb +16 -0
- data/test/integration/redirect_to_next_test.rb +1 -1
- data/test/integration/security_test.rb +0 -2
- data/test/integration/update_params_test.rb +20 -0
- data/test/integration/updates_test.rb +20 -0
- data/test/support/wicked_controller_test_case.rb +9 -0
- data/test/test_helper.rb +9 -9
- data/wicked.gemspec +22 -150
- data/wicked.png +0 -0
- metadata +156 -51
- data/.rvmrc +0 -19
- data/.travis.yml +0 -22
- data/VERSION +0 -1
- /data/test/dummy/app/controllers/{steps_controller.rb → step_positions_controller.rb} +0 -0
|
@@ -1,51 +1,63 @@
|
|
|
1
1
|
module Wicked::Controller::Concerns::RenderRedirect
|
|
2
2
|
extend ActiveSupport::Concern
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
process_resource!(resource)
|
|
4
|
+
def render_wizard(resource = nil, options = {}, params = {})
|
|
5
|
+
process_resource!(resource, options)
|
|
7
6
|
|
|
8
7
|
if @skip_to
|
|
9
|
-
|
|
8
|
+
url_params = (@wicked_redirect_params || {}).merge(params)
|
|
9
|
+
redirect_to wizard_path(@skip_to, url_params), options
|
|
10
10
|
else
|
|
11
|
-
render_step
|
|
11
|
+
render_step(wizard_value(step), options, params)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def process_resource!(resource)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
def process_resource!(resource, options = {})
|
|
16
|
+
return unless resource
|
|
17
|
+
|
|
18
|
+
if options[:context]
|
|
19
|
+
did_save = resource.save(context: options[:context])
|
|
20
|
+
else
|
|
21
|
+
did_save = resource.save
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
if did_save
|
|
25
|
+
@skip_to ||= @next_step
|
|
26
|
+
else
|
|
27
|
+
@skip_to = nil
|
|
28
|
+
# Do not override user-provided status for render
|
|
29
|
+
options[:status] ||= :unprocessable_entity
|
|
22
30
|
end
|
|
23
31
|
end
|
|
24
32
|
|
|
25
|
-
def render_step(the_step, options = {})
|
|
33
|
+
def render_step(the_step, options = {}, params = {})
|
|
26
34
|
if the_step.nil? || the_step.to_s == Wicked::FINISH_STEP
|
|
27
|
-
redirect_to_finish_wizard options
|
|
35
|
+
redirect_to_finish_wizard options, params
|
|
28
36
|
else
|
|
29
37
|
render the_step, options
|
|
30
38
|
end
|
|
31
39
|
end
|
|
32
40
|
|
|
33
|
-
def redirect_to_next(next_step, options = {})
|
|
41
|
+
def redirect_to_next(next_step, options = {}, params = {})
|
|
34
42
|
if next_step.nil?
|
|
35
|
-
redirect_to_finish_wizard(options)
|
|
43
|
+
redirect_to_finish_wizard(options, params)
|
|
36
44
|
else
|
|
37
|
-
redirect_to wizard_path(next_step), options
|
|
45
|
+
redirect_to wizard_path(next_step, params), options
|
|
38
46
|
end
|
|
39
47
|
end
|
|
40
48
|
|
|
41
49
|
# TODO redirect to resource if one is passed to render_wizard
|
|
42
|
-
def finish_wizard_path
|
|
43
|
-
'/'
|
|
50
|
+
def finish_wizard_path(params = {})
|
|
51
|
+
url = '/'
|
|
52
|
+
url = "#{url}?#{params.to_query}" unless params.blank?
|
|
53
|
+
url
|
|
44
54
|
end
|
|
45
55
|
|
|
46
|
-
def redirect_to_finish_wizard(options = {})
|
|
47
|
-
|
|
48
|
-
|
|
56
|
+
def redirect_to_finish_wizard(options = {}, params = {})
|
|
57
|
+
wicked_final_redirect_path = method(:finish_wizard_path).arity == 1 ? finish_wizard_path(params) : finish_wizard_path
|
|
58
|
+
Rails.logger.debug("Wizard has finished, redirecting to finish_wizard_path: #{wicked_final_redirect_path.inspect}")
|
|
59
|
+
# flash.keep is required for Rails 3 where a flash message is lost on a second redirect.
|
|
60
|
+
flash.keep
|
|
61
|
+
redirect_to wicked_final_redirect_path, options
|
|
49
62
|
end
|
|
50
63
|
end
|
|
51
|
-
|
|
@@ -3,12 +3,14 @@ module Wicked::Controller::Concerns::Steps
|
|
|
3
3
|
|
|
4
4
|
extend ActiveSupport::Concern
|
|
5
5
|
|
|
6
|
-
def jump_to(goto_step)
|
|
7
|
-
@skip_to
|
|
6
|
+
def jump_to(goto_step, options = {})
|
|
7
|
+
@skip_to = goto_step
|
|
8
|
+
@wicked_redirect_params = options
|
|
8
9
|
end
|
|
9
10
|
|
|
10
|
-
def skip_step
|
|
11
|
-
@skip_to
|
|
11
|
+
def skip_step(options = {})
|
|
12
|
+
@skip_to = @next_step
|
|
13
|
+
@wicked_redirect_params = options
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
def step
|
|
@@ -50,8 +52,8 @@ module Wicked::Controller::Concerns::Steps
|
|
|
50
52
|
options = args.extract_options!
|
|
51
53
|
steps = args
|
|
52
54
|
check_protected!(steps)
|
|
53
|
-
|
|
54
|
-
self.steps = steps
|
|
55
|
+
prepend_before_action(options) do
|
|
56
|
+
self.steps = steps.dup
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
|
|
@@ -79,31 +81,24 @@ module Wicked::Controller::Concerns::Steps
|
|
|
79
81
|
index = steps.index(current_step)
|
|
80
82
|
step = steps.at(index - 1) if index.present? && index != 0
|
|
81
83
|
step ||= steps.first
|
|
82
|
-
step
|
|
83
84
|
end
|
|
84
85
|
|
|
85
|
-
|
|
86
86
|
def next_step(current_step = nil)
|
|
87
87
|
return @next_step if current_step.nil?
|
|
88
88
|
index = steps.index(current_step)
|
|
89
89
|
step = steps.at(index + 1) if index.present?
|
|
90
90
|
step ||= Wicked::FINISH_STEP
|
|
91
|
-
step
|
|
92
91
|
end
|
|
93
92
|
|
|
94
|
-
private
|
|
95
|
-
|
|
96
|
-
def step_index_for(step_name)
|
|
93
|
+
private def step_index_for(step_name)
|
|
97
94
|
steps.index(step_name)
|
|
98
95
|
end
|
|
99
96
|
|
|
100
|
-
def current_step_index
|
|
97
|
+
private def current_step_index
|
|
101
98
|
step_index_for(step)
|
|
102
99
|
end
|
|
103
100
|
|
|
104
|
-
def current_and_given_step_exists?(step_name)
|
|
105
|
-
|
|
106
|
-
return true
|
|
101
|
+
private def current_and_given_step_exists?(step_name)
|
|
102
|
+
current_step_index.present? && steps.index(step_name).present?
|
|
107
103
|
end
|
|
108
104
|
end
|
|
109
|
-
|
|
@@ -5,8 +5,8 @@ module Wicked
|
|
|
5
5
|
include Wicked::Wizard
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
skip_before_action :setup_wizard
|
|
9
|
+
before_action :setup_wizard_translated
|
|
10
10
|
|
|
11
11
|
helper_method :wizard_translate, :wizard_value
|
|
12
12
|
end
|
|
@@ -57,7 +57,6 @@ module Wicked
|
|
|
57
57
|
end
|
|
58
58
|
|
|
59
59
|
|
|
60
|
-
private
|
|
61
60
|
# sets up a translated wizard controller
|
|
62
61
|
# translations are expected under the 'wicked' namespace
|
|
63
62
|
#
|
|
@@ -74,12 +73,10 @@ module Wicked
|
|
|
74
73
|
#
|
|
75
74
|
# steps "wicked.first", "wicked.second"
|
|
76
75
|
#
|
|
77
|
-
def setup_wizard_translated
|
|
76
|
+
private def setup_wizard_translated
|
|
78
77
|
self.steps = wizard_translations.keys # must come before setting previous/next steps
|
|
79
78
|
setup_wizard
|
|
80
79
|
end
|
|
81
|
-
public
|
|
82
80
|
end
|
|
83
81
|
end
|
|
84
82
|
end
|
|
85
|
-
|
data/lib/wicked/wizard.rb
CHANGED
|
@@ -3,14 +3,18 @@ module Wicked
|
|
|
3
3
|
extend ActiveSupport::Concern
|
|
4
4
|
|
|
5
5
|
class InvalidStepError < RuntimeError
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
attr_accessor :step
|
|
7
|
+
|
|
8
|
+
def initialize(step = nil)
|
|
9
|
+
self.step = step
|
|
10
|
+
|
|
11
|
+
super "The requested step did not match any steps defined for this controller: #{step.inspect}"
|
|
8
12
|
end
|
|
9
13
|
end
|
|
10
14
|
|
|
11
15
|
class UndefinedStepsError < RuntimeError
|
|
12
16
|
def initialize
|
|
13
|
-
super "No step definitions have been supplied; if setting via `
|
|
17
|
+
super "No step definitions have been supplied; if setting via `before_action`, use `prepend_before_action`"
|
|
14
18
|
end
|
|
15
19
|
end
|
|
16
20
|
|
|
@@ -20,19 +24,19 @@ module Wicked
|
|
|
20
24
|
include Wicked::Controller::Concerns::Steps
|
|
21
25
|
|
|
22
26
|
included do
|
|
27
|
+
include Wicked::Controller::Concerns::Action
|
|
23
28
|
# Give our Views helper methods!
|
|
24
|
-
helper_method :wizard_path,
|
|
25
|
-
:step,
|
|
26
|
-
:
|
|
27
|
-
|
|
29
|
+
helper_method :wizard_path, :wizard_url, :next_wizard_path, :next_wizard_url, :previous_wizard_path,
|
|
30
|
+
:previous_wizard_url, :step, :wizard_steps, :current_step?, :past_step?, :future_step?,
|
|
31
|
+
:next_step?, :previous_step?
|
|
32
|
+
|
|
28
33
|
# Set @step and @next_step variables
|
|
29
|
-
|
|
34
|
+
before_action :initialize_wicked_variables, :setup_wizard
|
|
30
35
|
end
|
|
31
36
|
|
|
32
37
|
# forward to first step with whatever params are provided
|
|
33
38
|
def index
|
|
34
|
-
|
|
35
|
-
redirect_to "#{ wizard_path(steps.first) }#{ query_string || '' }"
|
|
39
|
+
redirect_to wizard_path(steps.first, request.query_parameters)
|
|
36
40
|
end
|
|
37
41
|
|
|
38
42
|
# returns the canonical value for a step name, needed for translation support
|
|
@@ -40,43 +44,44 @@ module Wicked
|
|
|
40
44
|
step_name
|
|
41
45
|
end
|
|
42
46
|
|
|
43
|
-
private
|
|
47
|
+
private def initialize_wicked_variables
|
|
48
|
+
@skip_to = nil
|
|
49
|
+
@wicked_redirect_params = nil
|
|
50
|
+
end
|
|
44
51
|
|
|
45
|
-
def check_redirect_to_first_last!(step)
|
|
52
|
+
private def check_redirect_to_first_last!(step)
|
|
46
53
|
redirect_to wizard_path(steps.first) if step.to_s == Wicked::FIRST_STEP
|
|
47
54
|
redirect_to wizard_path(steps.last) if step.to_s == Wicked::LAST_STEP
|
|
48
55
|
end
|
|
49
56
|
|
|
50
|
-
def setup_step_from(the_step)
|
|
57
|
+
private def setup_step_from(the_step)
|
|
51
58
|
return if steps.nil?
|
|
52
59
|
|
|
53
60
|
the_step ||= steps.first
|
|
54
61
|
check_redirect_to_first_last!(the_step)
|
|
55
62
|
|
|
56
63
|
valid_steps = steps + self.class::PROTECTED_STEPS
|
|
57
|
-
|
|
64
|
+
resolved_step = valid_steps.detect { |stp| stp.to_s == the_step }
|
|
58
65
|
|
|
59
|
-
raise InvalidStepError if
|
|
60
|
-
|
|
66
|
+
raise InvalidStepError.new(the_step) if resolved_step.nil?
|
|
67
|
+
resolved_step
|
|
61
68
|
end
|
|
62
69
|
|
|
63
|
-
def check_steps!
|
|
70
|
+
private def check_steps!
|
|
64
71
|
raise UndefinedStepsError if steps.nil?
|
|
65
72
|
end
|
|
66
73
|
|
|
67
|
-
def set_previous_next(step)
|
|
68
|
-
@previous_step = previous_step(
|
|
69
|
-
@next_step = next_step(
|
|
74
|
+
private def set_previous_next(step)
|
|
75
|
+
@previous_step = previous_step(step)
|
|
76
|
+
@next_step = next_step(step)
|
|
70
77
|
end
|
|
71
78
|
|
|
72
|
-
def setup_wizard
|
|
79
|
+
private def setup_wizard
|
|
73
80
|
check_steps!
|
|
74
81
|
return if params[:id].nil?
|
|
75
82
|
|
|
76
83
|
@step = setup_step_from(params[:id])
|
|
77
84
|
set_previous_next(@step)
|
|
78
85
|
end
|
|
79
|
-
public
|
|
80
86
|
end
|
|
81
87
|
end
|
|
82
|
-
|
data/lib/wicked.rb
CHANGED
|
@@ -13,6 +13,7 @@ module Wicked
|
|
|
13
13
|
end
|
|
14
14
|
module Wizard
|
|
15
15
|
end
|
|
16
|
+
autoload :WizardController, "wicked/wizard_controller"
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
class WickedError < StandardError; end
|
|
@@ -21,7 +22,7 @@ class WickedProtectedStepError < WickedError; end
|
|
|
21
22
|
require 'wicked/controller/concerns/render_redirect'
|
|
22
23
|
require 'wicked/controller/concerns/steps'
|
|
23
24
|
require 'wicked/controller/concerns/path'
|
|
25
|
+
require 'wicked/controller/concerns/action'
|
|
24
26
|
require 'wicked/wizard'
|
|
25
27
|
require 'wicked/wizard/translated'
|
|
26
28
|
require 'wicked/engine'
|
|
27
|
-
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
class BarControllerTest <
|
|
3
|
+
class BarControllerTest < WickedControllerTestCase
|
|
4
|
+
|
|
4
5
|
test 'index redirects to the first step' do
|
|
5
6
|
get :index
|
|
6
7
|
assert_redirected_to bar_path(:first)
|
|
7
8
|
end
|
|
8
9
|
|
|
9
10
|
test 'index redirects to the first step, preserving query args' do
|
|
10
|
-
get :index, :some => 'arguments', :were => 'passed'
|
|
11
|
+
get :index, params: { :some => 'arguments', :were => 'passed' }
|
|
11
12
|
assert_redirected_to bar_path(:first, :some => 'arguments', :were => 'passed')
|
|
12
13
|
end
|
|
13
14
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class StatusCodesControllerTest < WickedControllerTestCase
|
|
4
|
+
test 'returns successful status code for show' do
|
|
5
|
+
get :show, params: { id: 'good' }
|
|
6
|
+
assert_response(:success)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
test 'returns correct status code for successfuly update' do
|
|
10
|
+
put :update, params: { id: 'good' }
|
|
11
|
+
assert_response(:redirect)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'returns correct status code for failed update' do
|
|
15
|
+
put :update, params: { id: 'bad' }
|
|
16
|
+
assert_response(:unprocessable_entity)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class UpdatesControllerTest < WickedControllerTestCase
|
|
4
|
+
test 'redirect from first step to second step' do
|
|
5
|
+
put :update, params: {:id => 'first'}
|
|
6
|
+
assert_redirected_to update_path(:second)
|
|
7
|
+
assert_equal 'Thing was updated from step first.', flash[:notice]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
test 'redirect from second step to final step' do
|
|
11
|
+
put :update, params: {:id => 'second'}
|
|
12
|
+
assert_redirected_to update_path(:last_step)
|
|
13
|
+
assert_equal 'Thing was updated from step second.', flash[:notice]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
test 'redirect from last_step to root path' do
|
|
17
|
+
put :update, params: {:id => 'last_step'}
|
|
18
|
+
assert_redirected_to update_path(:wicked_finish)
|
|
19
|
+
assert_equal 'Thing was updated from step last_step.', flash[:notice]
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test 'redirect from wicked_finish to root path' do
|
|
23
|
+
get :show, params: {:id => Wicked::FINISH_STEP}, flash: {:notice => "flash from last_step"}
|
|
24
|
+
assert_redirected_to updates_path
|
|
25
|
+
assert_equal 'flash from last_step', flash[:notice]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
class ApplicationController < ActionController::Base
|
|
2
2
|
protect_from_forgery
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
if respond_to? :before_action
|
|
4
|
+
before_action :pull_out_locale
|
|
5
|
+
else
|
|
6
|
+
before_filter :pull_out_locale
|
|
7
|
+
end
|
|
5
8
|
|
|
6
9
|
def pull_out_locale
|
|
7
10
|
I18n.locale = params[:locale] if params[:locale].present?
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class DynamicDifferentStepsController < ApplicationController
|
|
2
|
+
include Wicked::Wizard
|
|
3
|
+
|
|
4
|
+
before_action :set_steps
|
|
5
|
+
before_action :setup_wizard
|
|
6
|
+
|
|
7
|
+
def show
|
|
8
|
+
render_wizard
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
def set_steps
|
|
14
|
+
self.steps = if params[:steps]
|
|
15
|
+
params[:steps]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -5,8 +5,8 @@ class JumpController < ApplicationController
|
|
|
5
5
|
steps :first, :second, :last_step
|
|
6
6
|
|
|
7
7
|
def show
|
|
8
|
-
skip_step if params[:skip_step]
|
|
9
|
-
jump_to :last_step if params[:jump_to]
|
|
8
|
+
skip_step(skip_step_options) if params[:skip_step]
|
|
9
|
+
jump_to :last_step, skip_step_options if params[:jump_to]
|
|
10
10
|
if params[:resource]
|
|
11
11
|
value = params[:resource][:save] == 'true'
|
|
12
12
|
@bar = Bar.new(value)
|
|
@@ -19,4 +19,11 @@ class JumpController < ApplicationController
|
|
|
19
19
|
def update
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def skip_step_options
|
|
25
|
+
options = params[:skip_step_options]
|
|
26
|
+
options.permit! if options.respond_to? :permitted?
|
|
27
|
+
options
|
|
28
|
+
end
|
|
22
29
|
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
class StatusCodesController < ApplicationController
|
|
2
|
+
include Wicked::Wizard
|
|
3
|
+
|
|
4
|
+
class GoodThing
|
|
5
|
+
def save
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class BadThing
|
|
11
|
+
def save
|
|
12
|
+
false
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
steps :good, :bad
|
|
17
|
+
|
|
18
|
+
def index; end
|
|
19
|
+
|
|
20
|
+
def show
|
|
21
|
+
render_wizard
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def update
|
|
25
|
+
case step
|
|
26
|
+
when :good
|
|
27
|
+
@thing = GoodThing.new
|
|
28
|
+
when :bad
|
|
29
|
+
@thing = BadThing.new
|
|
30
|
+
end
|
|
31
|
+
render_wizard(@thing, notice: "Thing was updated from step #{step}.")
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
|
|
36
|
+
def finish_wizard_path
|
|
37
|
+
updates_path
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class UpdateParamsController < ApplicationController
|
|
2
|
+
include Wicked::Wizard
|
|
3
|
+
|
|
4
|
+
class Thing
|
|
5
|
+
def save
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
steps :first, :second, :last_step
|
|
11
|
+
|
|
12
|
+
def index
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def show
|
|
17
|
+
render_wizard(nil, {}, { one: 'two' })
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update
|
|
21
|
+
@thing = Thing.new
|
|
22
|
+
render_wizard(@thing, { notice: "Thing was updated from step #{step}." }, { one: 'two' })
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def finish_wizard_path(params)
|
|
28
|
+
update_params_path(params)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
class UpdatesController < ApplicationController
|
|
2
|
+
include Wicked::Wizard
|
|
3
|
+
|
|
4
|
+
class Thing
|
|
5
|
+
def save
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
steps :first, :second, :last_step
|
|
11
|
+
|
|
12
|
+
def index
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def show
|
|
17
|
+
render_wizard
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def update
|
|
21
|
+
@thing = Thing.new
|
|
22
|
+
render_wizard(@thing, notice: "Thing was updated from step #{step}.")
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def finish_wizard_path
|
|
28
|
+
updates_path
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -4,4 +4,6 @@ first
|
|
|
4
4
|
<%= "params[:foo] #{params[:foo]}" %>
|
|
5
5
|
<%= link_to 'last', wizard_path(:last_step) %>
|
|
6
6
|
<%= link_to 'current', wizard_path %>
|
|
7
|
-
<%= link_to '
|
|
7
|
+
<%= link_to 'current url', wizard_url %>
|
|
8
|
+
<%= link_to 'skip', next_wizard_path %>
|
|
9
|
+
<%= link_to 'next url', next_wizard_url %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
bad step
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
good step
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<% wizard_steps.each do |s| %>
|
|
2
|
+
<%= s.inspect %>
|
|
3
|
+
<%= I18n.t("wicked.#{s}") %>
|
|
4
|
+
<p>
|
|
5
|
+
<strong><u><%= s.inspect %></u></strong><br />
|
|
6
|
+
<%= current_step?(s) ? "#{s} step is the current step" : "nope" %><br />
|
|
7
|
+
<%= past_step?(s) ? "#{s} step is a past step" : "nope" %><br />
|
|
8
|
+
<%= future_step?(s) ? "#{s} step is a future step" : "nope" %><br />
|
|
9
|
+
<%= previous_step?(s) ? "#{s} step was the previous step" : "nope" %><br />
|
|
10
|
+
<%= next_step?(s) ? "#{s} step is the next step" : "nope" %><br />
|
|
11
|
+
</p>
|
|
12
|
+
<% end %>
|
|
13
|
+
|
|
14
|
+
<%= form_tag update_param_path(step, {one: 'two'}), :method => :put do %>
|
|
15
|
+
<%= submit_tag "Next" %>
|
|
16
|
+
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'step_position' %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Index page.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'step_position' %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'step_position' %>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<% wizard_steps.each do |s| %>
|
|
2
|
+
<%= s.inspect %>
|
|
3
|
+
<%= I18n.t("wicked.#{s}") %>
|
|
4
|
+
<p>
|
|
5
|
+
<strong><u><%= s.inspect %></u></strong><br />
|
|
6
|
+
<%= current_step?(s) ? "#{s} step is the current step" : "nope" %><br />
|
|
7
|
+
<%= past_step?(s) ? "#{s} step is a past step" : "nope" %><br />
|
|
8
|
+
<%= future_step?(s) ? "#{s} step is a future step" : "nope" %><br />
|
|
9
|
+
<%= previous_step?(s) ? "#{s} step was the previous step" : "nope" %><br />
|
|
10
|
+
<%= next_step?(s) ? "#{s} step is the next step" : "nope" %><br />
|
|
11
|
+
</p>
|
|
12
|
+
<% end %>
|
|
13
|
+
|
|
14
|
+
<%= form_tag update_path(step, {one: 'two'}), :method => :put do %>
|
|
15
|
+
<%= submit_tag "Next" %>
|
|
16
|
+
<% end %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'step_position' %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Index page.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'step_position' %>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= render 'step_position' %>
|