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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dbeda5baf3151daeee78f081393fcb7ad320a927c7c928b1a1af4940afe02580
4
- data.tar.gz: 62f16acb9a560d7b7abb946c02d72c6a021a7e790ae1d8abf984a5627e44a0f0
3
+ metadata.gz: 959442a013960f1f2a4cbe72191b4fc965f15cc416be00b4d8ba2f2349dca3f9
4
+ data.tar.gz: 7fa3a58b24e6c22bf27bcfc994dad3aa3f121795ccf6f18211839f18cfb99045
5
5
  SHA512:
6
- metadata.gz: fa3df3560e87aa90ad79e86664c14cfc1a4d44cd28474e43b3bfbc66032fe676531c444d3d3716421628a3590f7b7c32e6eb3f04d77ca324f4bd223630a1b225
7
- data.tar.gz: 4de2fedf514e70e5f37f5fa49e74bec3389dfed6626eb848180d90b2fa216963db372ab55bad53f0b6cedddaac9b93d3c29ed80045960ac356226311ae121996
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
  ![title image](title_image.png)
@@ -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(:"@#{turbo_form_resource_name}", resource)
39
+ instance_variable_set(turbo_form_ivar, resource)
35
40
  end
36
41
 
37
- def turbo_form_resource = instance_variable_get(:"@#{turbo_form_resource_name}")
38
- def turbo_form_resource_params = send(:"#{turbo_form_resource_name}_params")
39
- def turbo_form_resource_name = controller_name.singularize
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.
@@ -1,3 +1,3 @@
1
1
  module TurboForm
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Cohen