turbo_form 0.10.0 → 0.11.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 +4 -4
- data/README.md +17 -0
- data/lib/turbo_form/controller.rb +10 -5
- data/lib/turbo_form/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 959442a013960f1f2a4cbe72191b4fc965f15cc416be00b4d8ba2f2349dca3f9
|
|
4
|
+
data.tar.gz: 7fa3a58b24e6c22bf27bcfc994dad3aa3f121795ccf6f18211839f18cfb99045
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a62fcaf048717ca8261bac7e79a4c831bce7d02e9b0c0e6f689c3fe01d7966eeff9a4ed771977c703984b45e45b9ba1282f397ed2ba3b2a29a1f29ddb05dd7d2
|
|
7
|
+
data.tar.gz: 3a5c4756db5d7c1685733877e424198d6a338065bd51c79f2f2cb4d67c0875bb005bd9918835ab4125b65920ab50860a64e04488b14671b7d7eae41adb4e01c6
|
data/README.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# turbo_form
|
|
2
2
|
|
|
3
|
+
<div>
|
|
4
|
+
<img src="https://github.com/OutlawAndy/turbo_form/actions/workflows/ci.yml/badge.svg" alt="CI">
|
|
5
|
+
<img src="https://img.shields.io/gem/v/turbo_form?label=rubygems" alt="RubyGems">
|
|
6
|
+
<img src="https://img.shields.io/npm/v/@rolemodel/turbo-form?label=npm" alt="npm">
|
|
7
|
+
</div>
|
|
8
|
+
<br/>
|
|
9
|
+
|
|
3
10
|
Dynamic forms for Rails, by convention.
|
|
4
11
|
|
|
5
12
|

|
|
@@ -157,6 +164,16 @@ For a `WidgetsController`:
|
|
|
157
164
|
themselves — `render layout: 'panel'` is fine. The values are assigned just
|
|
158
165
|
before it renders; an action that redirects still redirects.
|
|
159
166
|
|
|
167
|
+
When `new` and `edit` build the form's object under another name — a bulk form
|
|
168
|
+
object in `@form`, say, where `@widget` already means one of the records it
|
|
169
|
+
wraps — name it, and `widget_params` still permits it:
|
|
170
|
+
|
|
171
|
+
```ruby
|
|
172
|
+
class WidgetsController < ApplicationController
|
|
173
|
+
self.turbo_form_resource_name = :form
|
|
174
|
+
end
|
|
175
|
+
```
|
|
176
|
+
|
|
160
177
|
### Switching an STI subclass
|
|
161
178
|
|
|
162
179
|
When the submitted values include the inheritance column, the object is switched
|
|
@@ -5,12 +5,17 @@ module TurboForm
|
|
|
5
5
|
# implicitly, or with its own `render layout: 'panel'`.
|
|
6
6
|
#
|
|
7
7
|
# Leans on the scaffold's conventions: the action builds `@<resource>` and
|
|
8
|
-
# `<resource>_params` permits the form.
|
|
8
|
+
# `<resource>_params` permits the form. A controller whose form object goes by
|
|
9
|
+
# another name sets `self.turbo_form_resource_name = :form`.
|
|
9
10
|
module Controller
|
|
10
11
|
extend ActiveSupport::Concern
|
|
11
12
|
|
|
12
13
|
included do
|
|
13
14
|
helper_method :turbo_form_render?
|
|
15
|
+
|
|
16
|
+
# The instance variable `new` and `edit` build the form's object in, when
|
|
17
|
+
# it isn't the controller's namesake.
|
|
18
|
+
class_attribute :turbo_form_resource_name, instance_accessor: false
|
|
14
19
|
end
|
|
15
20
|
|
|
16
21
|
# Public, as Rails' own is. ActionController::Base's public methods are never
|
|
@@ -31,12 +36,12 @@ module TurboForm
|
|
|
31
36
|
|
|
32
37
|
def dynamic_form_assignment
|
|
33
38
|
resource = turbo_form_resource.extend(TurboForm::Resource).dynamic_assign(turbo_form_resource_params)
|
|
34
|
-
instance_variable_set(
|
|
39
|
+
instance_variable_set(turbo_form_ivar, resource)
|
|
35
40
|
end
|
|
36
41
|
|
|
37
|
-
def turbo_form_resource = instance_variable_get(
|
|
38
|
-
def turbo_form_resource_params = send(:"#{
|
|
39
|
-
def
|
|
42
|
+
def turbo_form_resource = instance_variable_get(turbo_form_ivar)
|
|
43
|
+
def turbo_form_resource_params = send(:"#{controller_name.singularize}_params")
|
|
44
|
+
def turbo_form_ivar = :"@#{self.class.turbo_form_resource_name || controller_name.singularize}"
|
|
40
45
|
|
|
41
46
|
# Active Record saves `has_many` writers and `*_ids=` on assignment, and
|
|
42
47
|
# this request exists only to render.
|
data/lib/turbo_form/version.rb
CHANGED