wicked 1.0.3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eb950926820837e2ebfd752237b01d22a38186c6073642f9c2c3fbf94da96fb3
|
4
|
+
data.tar.gz: 8eddcdf3391ac3d8e881c75624b431cafb54ccc956d488f6a1f975f02aff0c8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b33ad97299a460547b255c6774c6961d0c6ee0d9721ca9db04dbc26b7e37b606aaddd7a8a93dda1e6bc60e2b3418ac103bbca53bd76815cf65796acaaabc32fe
|
7
|
+
data.tar.gz: 4d5c337fb136b16a2468ba1f456f77db7f73600280fa5966e5c9f4d95bf01932aa61fb0bc5651a13974d259513dc7d6e353287e8b1daaf3488a6db157a7f1016
|
@@ -0,0 +1,13 @@
|
|
1
|
+
name: Check Changelog
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
types: [opened, reopened, edited, synchronize]
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v1
|
11
|
+
- name: Check that CHANGELOG is touched
|
12
|
+
run: |
|
13
|
+
cat $GITHUB_EVENT_PATH | jq .pull_request.title | grep -i '\[\(\(changelog skip\)\|\(ci skip\)\)\]' || git diff remotes/origin/${{ github.base_ref }} --name-only | grep CHANGELOG.md
|
@@ -0,0 +1,53 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
- push
|
5
|
+
- pull_request
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
strategy:
|
11
|
+
fail-fast: false
|
12
|
+
matrix:
|
13
|
+
ruby:
|
14
|
+
- '2.5'
|
15
|
+
- '2.6'
|
16
|
+
- '2.7'
|
17
|
+
- '3.0'
|
18
|
+
- '3.1'
|
19
|
+
# - 'head'
|
20
|
+
gemfile:
|
21
|
+
- gemfiles/rails_5.2.gemfile
|
22
|
+
- gemfiles/rails_6.0.gemfile
|
23
|
+
- gemfiles/rails_7.0.gemfile
|
24
|
+
# - gemfile: gemfiles/rails_head.gemfile
|
25
|
+
exclude:
|
26
|
+
- ruby: '2.5'
|
27
|
+
gemfile: gemfiles/rails_7.0.gemfile
|
28
|
+
- ruby: '2.6'
|
29
|
+
gemfile: gemfiles/rails_7.0.gemfile
|
30
|
+
- ruby: '2.7'
|
31
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
32
|
+
- ruby: '3.0'
|
33
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
34
|
+
- ruby: '3.0'
|
35
|
+
gemfile: gemfiles/rails_6.0.gemfile
|
36
|
+
- ruby: '3.1'
|
37
|
+
gemfile: gemfiles/rails_5.2.gemfile
|
38
|
+
- ruby: '3.1'
|
39
|
+
gemfile: gemfiles/rails_6.0.gemfile
|
40
|
+
steps:
|
41
|
+
- name: Checkout code
|
42
|
+
uses: actions/checkout@v3
|
43
|
+
- name: Set up Ruby
|
44
|
+
env:
|
45
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
46
|
+
uses: ruby/setup-ruby@v1
|
47
|
+
with:
|
48
|
+
ruby-version: ${{ matrix.ruby }}
|
49
|
+
bundler-cache: true
|
50
|
+
- name: Run test
|
51
|
+
env:
|
52
|
+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
|
53
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/Appraisals
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,48 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
* Return `422` (`:unprocessable_entity`) when form submissions fails. Turbo requires an HTTP Status code between 400-499 or 500-599 when a FormSubmission request fails. This pull request makes wicked compatible with Turbo Drive (https://github.com/zombocom/wicked/pull/294)
|
6
|
+
* Pass the provided step when raising InvalidStepError errors (https://github.com/zombocom/wicked/pull/284)
|
7
|
+
|
8
|
+
## 1.4.0
|
9
|
+
|
10
|
+
* Update readme to include `current_step?` (https://github.com/zombocom/wicked/pull/271)
|
11
|
+
* Add `*_url` versions of `wizard_path`, `next_wizard_path`, and `previous_wizard_path` (https://github.com/zombocom/wicked/pull/272)
|
12
|
+
|
13
|
+
## 1.3.4
|
14
|
+
|
15
|
+
* Remove arity check for AR objects (https://github.com/schneems/wicked/pull/257)
|
16
|
+
|
17
|
+
## 1.3.3
|
18
|
+
|
19
|
+
* Support being able to set a context in validation (https://github.com/schneems/wicked/pull/236)
|
20
|
+
|
21
|
+
## 1.3.2
|
22
|
+
|
23
|
+
* Support for params (#222)
|
24
|
+
|
25
|
+
## 1.3.1
|
26
|
+
|
27
|
+
* Docs and minor fixes
|
28
|
+
|
29
|
+
## 1.3.0
|
30
|
+
|
31
|
+
* [#201] Avoid Rails 5 deprecations.
|
32
|
+
|
33
|
+
## 1.2.1 (8/28/2015)
|
34
|
+
|
35
|
+
* [#186] Do not require use of ApplicationController with wicked.
|
36
|
+
|
37
|
+
## 1.1.1 (2/23/2015)
|
38
|
+
|
39
|
+
* [#159] Default wizard index actions now work when using `default_url_options`
|
40
|
+
|
41
|
+
## 1.1.0 (9/15/2014)
|
42
|
+
|
43
|
+
* [#136] `skip_step` and `jump_to` now take redirect options. You can use
|
44
|
+
this to effectively pass parameters to a redirect initiated by either of these method.
|
45
|
+
|
1
46
|
## 1.0.3 (4/25/2014)
|
2
47
|
|
3
48
|
* All `to_sym` have been removed. Symbol attacks are no longer possible.
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
There are two main ways to contribute to this project.
|
4
|
+
|
5
|
+
## Content
|
6
|
+
|
7
|
+
* Write articles
|
8
|
+
* Recording screencasts
|
9
|
+
* Submit presentations
|
10
|
+
|
11
|
+
## Development
|
12
|
+
|
13
|
+
Using [CodeTriage](http://www.codetriage.com/schneems/wicked) as a volunteer, you'll receive an email each day with a link to an open issue that needs to be triaged in this project. You'll also receive instructions on how to triage issues.
|
14
|
+
|
15
|
+
1. Fork it! ( https://github.com/schneems/wicked/fork )
|
16
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
17
|
+
3. Commit your changes: `git commit -am 'Add some feature'`
|
18
|
+
4. Push to the branch: `git push origin my-new-feature`
|
19
|
+
5. Create a new Pull Request :D
|
data/Gemfile
CHANGED
@@ -1,25 +1,8 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
rails = case rails_version
|
6
|
-
when "master"
|
7
|
-
{:github => "rails/rails"}
|
8
|
-
when "default"
|
9
|
-
">= 3.0.7"
|
10
|
-
else
|
11
|
-
"~> #{rails_version}"
|
12
|
-
end
|
13
|
-
|
14
|
-
gem "rails", rails
|
15
|
-
|
3
|
+
gemspec
|
16
4
|
|
17
5
|
group :development, :test do
|
18
|
-
gem
|
19
|
-
gem '
|
20
|
-
gem "capybara", "~> 1.1.2"
|
21
|
-
gem "launchy"
|
22
|
-
|
23
|
-
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
24
|
-
gem "activerecord-jdbcsqlite3-adapter", '>= 1.3.0.beta', :platform => :jruby
|
6
|
+
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
|
7
|
+
gem "activerecord-jdbcsqlite3-adapter", '~> 1.3.13', :platform => :jruby
|
25
8
|
end
|
data/README.md
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
![](
|
1
|
+
![](./wicked.png)
|
2
2
|
|
3
3
|
# Step-By-Step Wizard Controllers
|
4
4
|
|
5
|
-
[![Build Status](https://
|
6
|
-
[![Code Climate](https://codeclimate.com/github/schneems/wicked.
|
5
|
+
[![Build Status](https://github.com/zombocom/wicked/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/zombocom/wicked)
|
6
|
+
[![Code Climate](https://codeclimate.com/github/schneems/wicked/badges/gpa.svg)](https://codeclimate.com/github/schneems/wicked)
|
7
|
+
[![Help Contribute to Open Source](https://www.codetriage.com/schneems/wicked/badges/users.svg)](https://www.codetriage.com/schneems/wicked)
|
8
|
+
|
7
9
|
|
8
10
|
Use wicked to make your Rails controllers into step-by-step wizards. To see Wicked in action check out the example [Rails app](https://github.com/schneems/wicked_example) or [watch the screencast](http://schneems.com/post/18437886598/wizard-ify-your-rails-controllers-with-wicked).
|
9
11
|
|
@@ -28,6 +30,7 @@ Then run `bundle install` and you're ready to start
|
|
28
30
|
* [Show Current Wizard Progress to User](https://github.com/schneems/wicked/wiki/Show-Current-Wizard-Progress-to-User)
|
29
31
|
* [Example App](https://github.com/schneems/wicked_example)
|
30
32
|
* [Screencast](http://schneems.com/post/18437886598/wizard-ify-your-rails-controllers-with-wicked)
|
33
|
+
* [Devise Onboarding With Wicked by Deanin](https://www.youtube.com/watch?v=P-eYHvgT4KA)
|
31
34
|
* [Watch Railscasts episode: #346 Wizard Forms with Wicked](http://railscasts.com/episodes/346-wizard-forms-with-wicked)
|
32
35
|
|
33
36
|
## How
|
@@ -119,16 +122,23 @@ class AfterSignupController < ApplicationController
|
|
119
122
|
@user = current_user
|
120
123
|
case step
|
121
124
|
when :confirm_password
|
122
|
-
@user.
|
125
|
+
@user.update(user_params)
|
123
126
|
end
|
124
127
|
sign_in(@user, bypass: true) # needed for devise
|
125
128
|
render_wizard @user
|
126
129
|
end
|
130
|
+
|
131
|
+
private
|
132
|
+
def user_params
|
133
|
+
params.require(:user)
|
134
|
+
.permit(:email, :current_password) # ...
|
135
|
+
end
|
127
136
|
end
|
128
137
|
```
|
129
138
|
|
130
139
|
We're passing `render_wizard` our `@user` object here. If you pass an object into `render_wizard` it will show the next step if the object saves or re-render the previous view if it does not save.
|
131
140
|
|
141
|
+
Note that `render_wizard` does attempt to save the passed object. This means that in the above example, the object will be saved twice. This will cause any callbacks to run twice also. If this is undesirable for your use case, then calling `assign_attributes` (which does not save the object) instead of `update` might work better.
|
132
142
|
|
133
143
|
To get to this update action, you simply need to submit a form that PUT's to the same url
|
134
144
|
|
@@ -165,34 +175,61 @@ Now you've got a fully functioning AfterSignup controller! If you have questions
|
|
165
175
|
|
166
176
|
## Quick Reference
|
167
177
|
|
168
|
-
View/URL Helpers
|
178
|
+
**View/URL Helpers:**
|
169
179
|
|
170
180
|
```ruby
|
171
|
-
wizard_path #
|
172
|
-
wizard_path(:specific_step) #
|
173
|
-
next_wizard_path #
|
174
|
-
previous_wizard_path #
|
181
|
+
wizard_path # relative url of the current step
|
182
|
+
wizard_path(:specific_step) # relative url of a :specific_step
|
183
|
+
next_wizard_path # relative url of the next step
|
184
|
+
previous_wizard_path # relative url of the previous step
|
175
185
|
|
176
|
-
#
|
186
|
+
wizard_url # fully qualified url of the current step
|
187
|
+
wizard_url(:specific_step) # fully qualified url of a :specific_step
|
188
|
+
next_wizard_url # fully qualified url of the next step
|
189
|
+
previous_wizard_url # fully qualified url of the previous step
|
190
|
+
|
191
|
+
# These only work while in a Wizard
|
177
192
|
# You can have multiple wizards in a project with multiple `wizard_path` calls
|
178
193
|
```
|
179
194
|
|
180
195
|
|
181
|
-
Controller Tidbits
|
196
|
+
**Controller Tidbits:**
|
182
197
|
|
183
198
|
```ruby
|
184
|
-
steps :first, :second
|
185
|
-
step
|
186
|
-
next_step
|
187
|
-
previous_step
|
188
|
-
skip_step
|
189
|
-
jump_to(:specific_step)
|
190
|
-
render_wizard
|
191
|
-
render_wizard(@user)
|
199
|
+
steps :first, :second # Sets the order of steps
|
200
|
+
step # Gets current step
|
201
|
+
next_step # Gets next step
|
202
|
+
previous_step # Gets previous step
|
203
|
+
skip_step # Tells render_wizard to skip to the next logical step
|
204
|
+
jump_to(:specific_step) # Jump to :specific_step
|
205
|
+
render_wizard # Renders the current step
|
206
|
+
render_wizard(@user) # Shows next_step if @user.save, otherwise renders
|
207
|
+
render_wizard(@user, context: :account_setup) # Shows next_step if @user.save(context: :account_setup), otherwise renders
|
208
|
+
wizard_steps # Gets ordered list of steps
|
209
|
+
current_step?(step) # is step the same as the current request's step
|
210
|
+
past_step?(step) # does step come before the current request's step in wizard_steps
|
211
|
+
future_step?(step) # does step come after the current request's step in wizard_steps
|
212
|
+
previous_step?(step) # is step immediately before the current request's step
|
213
|
+
next_step?(step) # is step immediately after the current request's step
|
214
|
+
```
|
215
|
+
|
216
|
+
**Redirect options**
|
217
|
+
|
218
|
+
Both `skip_step` and `jump_to` will cause a redirect.
|
219
|
+
|
220
|
+
```
|
221
|
+
skip_step(foo: "bar")
|
192
222
|
```
|
193
223
|
|
224
|
+
*Note that unlike you would do when making a call to Rails' `redirect_to`, you should not call `return` immediately after `skip_step` and `jump_to`, since the actual redirection is done in the render_wizard call.*
|
194
225
|
|
195
|
-
|
226
|
+
If you want to pass params to the step you are skipping to you can pass it into those:
|
227
|
+
|
228
|
+
```
|
229
|
+
jump_to(:specific_step, foo: "bar")
|
230
|
+
```
|
231
|
+
|
232
|
+
**Finally:**
|
196
233
|
|
197
234
|
Don't forget to create your named views
|
198
235
|
|
@@ -206,7 +243,7 @@ app/
|
|
206
243
|
```
|
207
244
|
|
208
245
|
|
209
|
-
|
246
|
+
## Finish Wizard Path
|
210
247
|
|
211
248
|
You can specify the url that your user goes to by over-riding the `finish_wizard_path` in your wizard controller.
|
212
249
|
|
@@ -217,18 +254,16 @@ def finish_wizard_path
|
|
217
254
|
end
|
218
255
|
```
|
219
256
|
|
220
|
-
|
221
257
|
### Testing with RSpec
|
222
258
|
|
223
259
|
```ruby
|
224
260
|
# Test find_friends block of show action
|
225
|
-
get :show, id: :find_friends
|
261
|
+
get :show, params: { id: :find_friends }
|
226
262
|
|
227
263
|
# Test find_friends block of update action
|
228
|
-
|
264
|
+
patch :update, params: {'id' => 'find_friends', "user" => { "id" => @user.id.to_s }}
|
229
265
|
```
|
230
266
|
|
231
|
-
|
232
267
|
### Internationalization of URLS (I18n)
|
233
268
|
|
234
269
|
If your site works in multiple languages, or if you just want more control over how your URLs look you can now use I18n with wicked. To do so you need to replace this:
|
@@ -262,7 +297,7 @@ es:
|
|
262
297
|
It would also be a good idea to create a english version under `config/locales/en.yml` or your english speaking friends will get errors. If your app already uses I18n you don't need to do anything else, if not you will need to make sure that you set the `I18n.locale` on each request you could do this somewhere like a before filter in your application_controller.rb
|
263
298
|
|
264
299
|
```ruby
|
265
|
-
|
300
|
+
before_action :set_locale
|
266
301
|
|
267
302
|
private
|
268
303
|
|
@@ -305,7 +340,6 @@ end
|
|
305
340
|
|
306
341
|
Instead you need to use `wizard_value` to get the "reverse translation" in your controller code like this:
|
307
342
|
|
308
|
-
|
309
343
|
```ruby
|
310
344
|
steps :confirm_password, :confirm_profile, :find_friends
|
311
345
|
|
@@ -347,8 +381,9 @@ Now you can change the values in the URLs to whatever you want without changing
|
|
347
381
|
```ruby
|
348
382
|
config.i18n.default_locale = :de
|
349
383
|
```
|
384
|
+
|
350
385
|
**Important:** Don't forget to use `wizard_value()` method to make
|
351
|
-
sure you are using the right
|
386
|
+
sure you are using the right canonical values of `step`,
|
352
387
|
`previous_step`, `next_step`, etc. If you are comparing them to non
|
353
388
|
wicked generate values.
|
354
389
|
|
@@ -356,11 +391,12 @@ Custom crafted wizard urls: just another way Wicked makes your app a little more
|
|
356
391
|
|
357
392
|
## Dynamic Step Names
|
358
393
|
|
359
|
-
If you wish to set the order of your steps dynamically you can do this
|
394
|
+
If you wish to set the order of your steps dynamically you can do this by manually calling and `self.steps = [# <some steps> ]` in a `before_action` method. Then call `before_action :setup_wizard` after so that wicked knows when it is safe to initializelike this:
|
360
395
|
|
361
396
|
```ruby
|
362
397
|
include Wicked::Wizard
|
363
|
-
|
398
|
+
before_action :set_steps
|
399
|
+
before_action :setup_wizard
|
364
400
|
|
365
401
|
# ...
|
366
402
|
|
@@ -374,6 +410,41 @@ def set_steps
|
|
374
410
|
end
|
375
411
|
```
|
376
412
|
|
413
|
+
NOTE: The order of the `before_action` matters, when `setup_wizard` is called it will validate the presence of `self.steps`, you must call your custom step setting code before this point.
|
414
|
+
|
415
|
+
## Send params to finish_wizard_path method
|
416
|
+
|
417
|
+
If you wish to send parameters to the `finish_wizard_path` method that can be done by adding to your controller the method with the params argument `def finish_wizard_path(params) ... end`.
|
418
|
+
|
419
|
+
In order to send the parameters to the method here is an example of the show method:
|
420
|
+
|
421
|
+
```ruby
|
422
|
+
steps :first_step, :second_step
|
423
|
+
|
424
|
+
def show
|
425
|
+
# ...
|
426
|
+
render_wizard(nil, {}, { hello: 'world' })
|
427
|
+
end
|
428
|
+
|
429
|
+
def update
|
430
|
+
# ...
|
431
|
+
render_wizard(@user, {}, { hello: 'world' })
|
432
|
+
end
|
433
|
+
|
434
|
+
def finish_wizard_path(params)
|
435
|
+
# here you can access params and that would be equal to { hello: 'world' }
|
436
|
+
end
|
437
|
+
```
|
438
|
+
|
439
|
+
The `wizard_path` and `next_wizard_path` methods also take parameters that can then be accessed or visible in the `show` and `update` actions of the controller. You can use the methods like so:
|
440
|
+
|
441
|
+
```ruby
|
442
|
+
next_wizard_path({ hello: 'world' })
|
443
|
+
wizard_path(nil, { hello: 'world' })
|
444
|
+
# the wizard_path with the step specified would look like this
|
445
|
+
wizard_path(:wicked_finish, wizard_id: @user.id, hello: 'world')
|
446
|
+
```
|
447
|
+
|
377
448
|
## Keywords
|
378
449
|
|
379
450
|
There are a few "magical" keywords that will take you to the first step,
|
@@ -389,15 +460,59 @@ Wicked::FINISH_STEP
|
|
389
460
|
```
|
390
461
|
|
391
462
|
You can build links using these constants
|
392
|
-
`after_signup_path(Wicked::
|
463
|
+
`after_signup_path(Wicked::FIRST_STEP)` which will redirect the user to
|
393
464
|
the first step you've specified. This might be useful for redirecting a
|
394
465
|
user to a step when you're not already in a Wicked controller. If you
|
395
|
-
change the
|
466
|
+
change the constants, they are expected to be strings (not symbols).
|
396
467
|
|
397
|
-
##
|
468
|
+
## Support
|
469
|
+
|
470
|
+
Most problems using this library are general problems using Ruby/Rails. If you cannot get something to work correctly please open up a question on [stack overflow](http://stackoverflow.com/). If you've not posted there before, provide a description of the problem you're having and usually some example code and a copy of your rails logs helps.
|
398
471
|
|
399
|
-
|
472
|
+
If you've found a bug, please open a ticket on the issue tracker with a small example app that reproduces the behavior.
|
473
|
+
|
474
|
+
## About
|
400
475
|
|
401
|
-
|
476
|
+
Made by [@schneems](http://twitter.com/schneems).
|
402
477
|
|
403
478
|
This project rocks and uses MIT-LICENSE.
|
479
|
+
|
480
|
+
## Compatibility
|
481
|
+
|
482
|
+
Refer to the Travis CI test matrix for test using your version of Ruby and Rails. If there is a newer Ruby or Rails you don't see on there, please add an entry to the Appraisals file, then run `$ appraisals install` and update the `.travis.yml` file and send me a pull request.
|
483
|
+
|
484
|
+
Note: Rails 3.0 support is only for Ruby 1.9.3 or JRuby, not Ruby 2.0.0 or newer.
|
485
|
+
|
486
|
+
## Running Gem Tests
|
487
|
+
|
488
|
+
First, install the development gems:
|
489
|
+
|
490
|
+
```
|
491
|
+
$ bundle install
|
492
|
+
```
|
493
|
+
|
494
|
+
Now that `appraisal` is installed, use it to set up all the gemfiles for the test matrix:
|
495
|
+
|
496
|
+
```
|
497
|
+
$ appraisal install
|
498
|
+
```
|
499
|
+
|
500
|
+
Then to run tests against all the appraisal gemfiles, use:
|
501
|
+
|
502
|
+
```
|
503
|
+
$ appraisal rake test
|
504
|
+
```
|
505
|
+
|
506
|
+
To run tests against one specific gemfile,
|
507
|
+
use
|
508
|
+
|
509
|
+
```
|
510
|
+
$ appraisal 4.1 rake test
|
511
|
+
```
|
512
|
+
|
513
|
+
Note that Rails 3.0 tests don't pass in Ruby 2.0.0 or newer, so during development it may be easier to disable this
|
514
|
+
gemfile if you are using a current version of Ruby.
|
515
|
+
|
516
|
+
## Contributing
|
517
|
+
|
518
|
+
See the [Contributing guide](https://github.com/schneems/wicked/blob/master/CONTRIBUTING.md).
|
data/Rakefile
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'rubygems'
|
3
3
|
require 'bundler'
|
4
4
|
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
|
5
7
|
begin
|
6
8
|
Bundler.setup(:default, :development, :test)
|
7
9
|
rescue Bundler::BundlerError => e
|
@@ -33,18 +35,3 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
33
35
|
end
|
34
36
|
|
35
37
|
|
36
|
-
require 'jeweler'
|
37
|
-
Jeweler::Tasks.new do |gem|
|
38
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
39
|
-
gem.name = "wicked"
|
40
|
-
gem.homepage = "http://github.com/schneems/wicked"
|
41
|
-
gem.license = "MIT"
|
42
|
-
gem.summary = %Q{Use Wicked to turn your controller into a wizard}
|
43
|
-
gem.description = %Q{Wicked is a Rails engine for producing easy wizard controllers}
|
44
|
-
gem.email = "richard.schneeman@gmail.com"
|
45
|
-
gem.authors = ["schneems"]
|
46
|
-
# dependencies defined in Gemfile
|
47
|
-
end
|
48
|
-
Jeweler::RubygemsDotOrgTasks.new
|
49
|
-
|
50
|
-
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 5.2"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 6.0"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# This file was generated by Appraisal
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
gem "rails", "~> 7.0"
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem "sqlite3", platform: [:ruby, :mswin, :mingw]
|
9
|
+
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.13", platform: :jruby
|
10
|
+
end
|
11
|
+
|
12
|
+
gemspec path: "../"
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Wicked::Controller::Concerns::Action
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
def self.extended(base)
|
6
|
+
%w{before skip_before prepend_before}.each do |action|
|
7
|
+
define_method "#{action}_action" do |*names, &blk|
|
8
|
+
send("#{action}_filter", *names, &blk)
|
9
|
+
end unless base.respond_to? "#{action}_action"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,15 +1,22 @@
|
|
1
1
|
module Wicked::Controller::Concerns::Path
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
|
-
|
5
4
|
def next_wizard_path(options = {})
|
6
5
|
wizard_path(@next_step, options)
|
7
6
|
end
|
8
7
|
|
8
|
+
def next_wizard_url(options = {})
|
9
|
+
wizard_url(@next_step, options)
|
10
|
+
end
|
11
|
+
|
9
12
|
def previous_wizard_path(options = {})
|
10
13
|
wizard_path(@previous_step, options)
|
11
14
|
end
|
12
15
|
|
16
|
+
def previous_wizard_url(options = {})
|
17
|
+
wizard_url(@previous_step, options)
|
18
|
+
end
|
19
|
+
|
13
20
|
def wicked_controller
|
14
21
|
params[:controller]
|
15
22
|
end
|
@@ -18,8 +25,8 @@ module Wicked::Controller::Concerns::Path
|
|
18
25
|
params[:action]
|
19
26
|
end
|
20
27
|
|
21
|
-
|
22
28
|
def wizard_path(goto_step = nil, options = {})
|
29
|
+
options = options.respond_to?(:to_h) ? options.to_h : options
|
23
30
|
options = { :controller => wicked_controller,
|
24
31
|
:action => 'show',
|
25
32
|
:id => goto_step || params[:id],
|
@@ -27,5 +34,8 @@ module Wicked::Controller::Concerns::Path
|
|
27
34
|
}.merge options
|
28
35
|
url_for(options)
|
29
36
|
end
|
30
|
-
end
|
31
37
|
|
38
|
+
def wizard_url(goto_step = nil, options = {})
|
39
|
+
wizard_path(goto_step, options.merge(only_path: false))
|
40
|
+
end
|
41
|
+
end
|