superform 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -11
- data/lib/superform/rails.rb +7 -14
- data/lib/superform/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: 764fb4731b8ae1977a1e05ce0410302e5f29f3c008c4e0326f9b3f852118cb37
|
4
|
+
data.tar.gz: 6d7887d4b7b3bbf2af8ebfe7e675a155061e4982231d3f52caefd7a5e4c4c85d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edb3acf775edcaacb269b0aff7200d6bfd22d2c5701eb7dd0c96149bbc515acf33b77f586809ac574520a4330c1ed1acbe304e8c54d60a2b219e28b72179321b
|
7
|
+
data.tar.gz: e2b69ed000da6eeddeb3a47f664abfe052bbd85ae0e5649d23131b134d5d68acc9032fd4660260207540724c5fa10b85d6c6b4609484849e7c480a9fbd90bae1
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -144,14 +144,14 @@ Since Superforms are just Ruby objects, you can organize them however you want.
|
|
144
144
|
|
145
145
|
## Automatic strong parameters
|
146
146
|
|
147
|
-
Guess what? Superform eliminates then need for Strong Parameters in Rails by assigning the values of the `params` hash _through_ your form. Here's what it looks like.
|
147
|
+
Guess what? Superform eliminates then need for Strong Parameters in Rails by assigning the values of the `params` hash _through_ your form via the `assign` method. Here's what it looks like.
|
148
148
|
|
149
149
|
```ruby
|
150
150
|
class PostsController < ApplicationController
|
151
151
|
include Superform::Rails::StrongParameters
|
152
152
|
|
153
153
|
def create
|
154
|
-
@post = assign params.require(:post), to: Post.new
|
154
|
+
@post = assign params.require(:post), to: Posts::Form.new(Post.new)
|
155
155
|
|
156
156
|
if @post.save
|
157
157
|
# Success path
|
@@ -163,7 +163,7 @@ class PostsController < ApplicationController
|
|
163
163
|
def update
|
164
164
|
@post = Post.find(params[:id])
|
165
165
|
|
166
|
-
assign params.require(:post), to: @post
|
166
|
+
assign params.require(:post), to: Posts::Form.new(@post)
|
167
167
|
|
168
168
|
if @post.save
|
169
169
|
# Success path
|
@@ -171,14 +171,6 @@ class PostsController < ApplicationController
|
|
171
171
|
# Error path
|
172
172
|
end
|
173
173
|
end
|
174
|
-
|
175
|
-
private
|
176
|
-
# Defaults to `Posts::Form`, but you can override it here if
|
177
|
-
# you uncomment and add your own class. You could also pass the
|
178
|
-
# `form: FormClass` into the `assign` method.
|
179
|
-
#
|
180
|
-
# def form_class
|
181
|
-
# end
|
182
174
|
end
|
183
175
|
```
|
184
176
|
|
data/lib/superform/rails.rb
CHANGED
@@ -102,20 +102,13 @@ module Superform
|
|
102
102
|
|
103
103
|
module StrongParameters
|
104
104
|
protected
|
105
|
-
# Assigns params to the form model.
|
106
|
-
def assign(params, to
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
# Defaults to the form defined in `./app/views/*/form.rb`.
|
117
|
-
def form_class
|
118
|
-
self.controller_name.camelize.constantize::Form
|
105
|
+
# Assigns params to the form and returns the model.
|
106
|
+
def assign(params, to:)
|
107
|
+
form = to
|
108
|
+
# TODO: Figure out how to render this in a way that doesn't concat a string; just throw everything away.
|
109
|
+
render_to_string form
|
110
|
+
form.assign params
|
111
|
+
form.model
|
119
112
|
end
|
120
113
|
end
|
121
114
|
|
data/lib/superform/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brad Gessler
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-07-
|
11
|
+
date: 2023-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phlex-rails
|