effective_resources 1.6.5 → 1.6.6
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 +4 -4
- data/README.md +96 -0
- data/app/controllers/concerns/effective/wizard_controller.rb +3 -5
- data/lib/effective_resources/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 323b70f4a0eb470c2e96edf3651c83493763ad203659f03bb25832cf487812a1
|
4
|
+
data.tar.gz: f997c5dcd62f4de1d49065c5fb3d5d882ea3eca30c47fe518bb6642dbd43e65a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d78587039acac7fa236913c588946277481a5df90933141db13a7d447491233452f8dd6c3c96ebf7bff8dfd95ba217e56c65e826128d9674532331d6971422c
|
7
|
+
data.tar.gz: daff8c0e7009dd67297f2e62a90744b7dcc67008f107543b53c53b24476ca8534284202aae98b0579e394fddbdbb498925b0294f47c95e70f9bbf8b551cab4a3
|
data/README.md
CHANGED
@@ -256,6 +256,102 @@ end
|
|
256
256
|
|
257
257
|
and include Effective::CrudController in your resource controller.
|
258
258
|
|
259
|
+
### acts_as_wizard
|
260
|
+
|
261
|
+
Build up an object through a wizard.
|
262
|
+
|
263
|
+
Works with the [wicked](https://github.com/zombocom/wicked) gem to create wizard quickly.
|
264
|
+
|
265
|
+
Create a model and define `acts_as_wizard`:
|
266
|
+
|
267
|
+
```ruby
|
268
|
+
class Thing < ApplicationRecord
|
269
|
+
acts_as_wizard(
|
270
|
+
start: 'Start',
|
271
|
+
select: 'Select',
|
272
|
+
finish: 'Finish'
|
273
|
+
)
|
274
|
+
|
275
|
+
effective_resource do
|
276
|
+
title :string
|
277
|
+
wizard_steps :text, permitted: false
|
278
|
+
end
|
279
|
+
|
280
|
+
validates :title, presence: true
|
281
|
+
|
282
|
+
def to_s
|
283
|
+
title.presence || 'New Thing'
|
284
|
+
end
|
285
|
+
|
286
|
+
# If you define a bang method matching the name of a step
|
287
|
+
# it will be called when that step is submitted.
|
288
|
+
# Otherwise save! is called.
|
289
|
+
def select!
|
290
|
+
ApplicationMailer.selected(self).deliver_later
|
291
|
+
save!
|
292
|
+
end
|
293
|
+
|
294
|
+
# An array of steps that the controller will use
|
295
|
+
# Default value is just all of them. But you can customize here
|
296
|
+
# def required_steps
|
297
|
+
# steps = WIZARD_STEPS.keys
|
298
|
+
# selectable? ? steps : steps - [:select]
|
299
|
+
# end
|
300
|
+
|
301
|
+
# Control whether the user has permission to visit this step
|
302
|
+
#
|
303
|
+
# This is the default, can go forward or back:
|
304
|
+
#
|
305
|
+
# def can_visit_step?(step)
|
306
|
+
# can_revisit_completed_steps(step)
|
307
|
+
# end
|
308
|
+
#
|
309
|
+
# Easy change if you only want to go forward:
|
310
|
+
#
|
311
|
+
# def can_visit_step?(step)
|
312
|
+
# cannot_revisit_completed_steps(step)
|
313
|
+
# end
|
314
|
+
#
|
315
|
+
# or custom algorithm:
|
316
|
+
#
|
317
|
+
# def can_visit_step?(step)
|
318
|
+
# return false unless has_completed_previous_step?(step)
|
319
|
+
# return false if has_completed_step?(:finish) && step != :finish
|
320
|
+
# end
|
321
|
+
end
|
322
|
+
```
|
323
|
+
|
324
|
+
In your routes:
|
325
|
+
|
326
|
+
```ruby
|
327
|
+
resources :things, only: [:index, :show, :new, :destroy] do
|
328
|
+
resources :build, controller: :things, only: [:show, :update]
|
329
|
+
end
|
330
|
+
```
|
331
|
+
|
332
|
+
Make a controller:
|
333
|
+
|
334
|
+
```ruby
|
335
|
+
class ThingsController < ApplicationController
|
336
|
+
include Effective::WizardController
|
337
|
+
end
|
338
|
+
```
|
339
|
+
|
340
|
+
And then create one view per step.
|
341
|
+
|
342
|
+
Here's `views/things/start.html.haml`:
|
343
|
+
|
344
|
+
```haml
|
345
|
+
= render_wizard_sidebar(resource) do
|
346
|
+
%h1= @page_title
|
347
|
+
|
348
|
+
= effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
|
349
|
+
= f.text_field :title
|
350
|
+
= f.submit 'Save and Continue'
|
351
|
+
```
|
352
|
+
|
353
|
+
You can also call `render_wizard_sidebar(resource)` without the block syntax.
|
354
|
+
|
259
355
|
## Testing
|
260
356
|
|
261
357
|
Run tests by:
|
@@ -2,11 +2,7 @@ module Effective
|
|
2
2
|
module WizardController
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
|
6
|
-
raise("please install gem 'wicked' to use Effective::WizardController")
|
7
|
-
end
|
8
|
-
|
9
|
-
include Wicked::Wizard
|
5
|
+
include Wicked::Wizard if defined?(Wicked)
|
10
6
|
include Effective::CrudController
|
11
7
|
|
12
8
|
include Effective::WizardController::Actions
|
@@ -14,6 +10,8 @@ module Effective
|
|
14
10
|
include Effective::WizardController::Save
|
15
11
|
|
16
12
|
included do
|
13
|
+
raise("please install gem 'wicked' to use Effective::WizardController") unless defined?(Wicked)
|
14
|
+
|
17
15
|
with_options(only: [:show, :update]) do
|
18
16
|
before_action :redirect_if_blank_step
|
19
17
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|