Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/julianrubisch/sr-wizard-reflex
https://github.com/julianrubisch/sr-wizard-reflex
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/julianrubisch/sr-wizard-reflex
- Owner: julianrubisch
- License: mit
- Created: 2021-07-29T07:10:39.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-29T07:59:12.000Z (over 3 years ago)
- Last Synced: 2024-12-12T14:34:36.957Z (15 days ago)
- Language: Ruby
- Size: 49.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
Write powerful wizards using page morphs
**How?**
- An empty state model is memoized in the controller (`@book ||= Book.new(title: ...)`)
- A general purpose `WizardReflex` is used to step through the wizard and perist the model's state in the `session`
- A `@current_step` variable is in/decreased to display the current wizard pane.
- Validations are performed contextually, i.e. `on: :step_1`, etc.
- An _allowlist_ approach is used to centrally sanitize resource classes and strong params in that reflex.**Caveat**
In these examples, the amount of `steps` per wizard are hardcoded.
**Variations**
Enrich individual `WizardReflexes` with custom input processing logic:
```rb
class WizardReflex < ApplicationReflex
def refresh
additional_attributes, processed_resource_params = yield(resource_params) if block_given?session[:"new_#{resource_name.underscore}"] = resource_class.new(processed_resource_params || resource_params)
session[:"new_#{resource_name.underscore}"].assign_attributes(**additional_attributes || {})# ...
end
# ...
endclass BookReflex < WizardReflex
def refresh
super do |params|
[{isbn: '1234'}, params.except(...)]
end
end
end
```