rectify 0.5.4 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rectify/form.rb +4 -0
- data/lib/rectify/version.rb +1 -1
- data/readme.md +26 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8fedfe52a78eea51145b0f2d0a5e1edf6e92b25
|
4
|
+
data.tar.gz: e380f406cdb8c4de9883ecdc0ae62eb09c3eef44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96d0587eba88068ee4085979b976b398ff87902ba40710f902eaba16f06e57634626decca44fb3b3bfd0f687bdfa088e0062758fd1e3742e395d415875d55cd1
|
7
|
+
data.tar.gz: 6a9d47abdfc59d99ccd67914693969c8a1da62945e9a150edae77c38e830b8c9d8745c885743dd606ec85eb2dc84374abf1e38a7fbc6efb10cf81b52cf2a150d
|
data/lib/rectify/form.rb
CHANGED
data/lib/rectify/version.rb
CHANGED
data/readme.md
CHANGED
@@ -103,7 +103,7 @@ and Presenters.
|
|
103
103
|
|
104
104
|
## Form Objects
|
105
105
|
|
106
|
-
The role of the Form Object is to
|
106
|
+
The role of the Form Object is to manage the input data for a given action. It
|
107
107
|
validates data and only allows whitelisted attributes (replacing the need for
|
108
108
|
Strong Parameters). This is a departure from "The Rails Way" where the model
|
109
109
|
contains the validations. Form Objects help to reduce the weight of your models
|
@@ -283,7 +283,7 @@ form.ip_address # => "1.2.3.4"
|
|
283
283
|
|
284
284
|
**Model**
|
285
285
|
|
286
|
-
|
286
|
+
You can pass a Ruby object instance (which is normally an ActiveModel
|
287
287
|
but can be any PORO) to the form to populate it's attribute values. This is useful
|
288
288
|
when editing a model:
|
289
289
|
|
@@ -328,6 +328,30 @@ want to collect or show in your forms, not something that is linked to a model.
|
|
328
328
|
This allows you to create any form that you like which doesn't need to match the
|
329
329
|
representation of the data in the database.
|
330
330
|
|
331
|
+
**JSON**
|
332
|
+
|
333
|
+
You can also populate a form object from a JSON string. Just pass it in to the
|
334
|
+
`.from_json` class method and the form will be created with the attributes
|
335
|
+
populated by matching names:
|
336
|
+
|
337
|
+
```ruby
|
338
|
+
json = <<-JSON
|
339
|
+
{
|
340
|
+
"first_name": "Andy",
|
341
|
+
"age": 38
|
342
|
+
}
|
343
|
+
JSON
|
344
|
+
|
345
|
+
form = UserForm.from_json(json)
|
346
|
+
|
347
|
+
form.first_name # => "Andy"
|
348
|
+
form.age # => 38
|
349
|
+
```
|
350
|
+
|
351
|
+
Populating the form from JSON can be useful when dealing with API requests into
|
352
|
+
your system. Which allows you to easily access data and perform validation if
|
353
|
+
required.
|
354
|
+
|
331
355
|
### Validations
|
332
356
|
|
333
357
|
Rectify includes `ActiveModel::Validations` for you so you can use all of the
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rectify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Pike
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: virtus
|