You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+9-15Lines changed: 9 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ You probably want to use the same form for creating and editing resources. In Su
61
61
62
62
```ruby
63
63
# app/views/posts/form.rb
64
-
classPosts::Form < Components::Form
64
+
classViews::Posts::Form < Components::Form
65
65
defview_template
66
66
Field(:title).text
67
67
Field(:body).textarea(rows:10)
@@ -77,7 +77,7 @@ Then render this in your views:
77
77
```erb
78
78
<!-- app/views/posts/new.html.erb -->
79
79
<h1>New Post</h1>
80
-
<%= render Posts::Form.new @post %>
80
+
<%= render Views::Posts::Form.new @post %>
81
81
```
82
82
83
83
Cool, but you're about to score a huge benefit from extracting forms into their own Ruby classes with automatic strong parameters.
@@ -92,21 +92,14 @@ class PostsController < ApplicationController
92
92
93
93
defcreate
94
94
@post=Post.new
95
-
if save Posts::Form.new(@post)
95
+
if save Views::Posts::Form.new(@post)
96
96
redirect_to @post, notice:'Post created!'
97
97
else
98
98
render :new, status::unprocessable_entity
99
99
end
100
100
end
101
101
102
-
defupdate
103
-
@post=Post.find(params[:id])
104
-
if save Posts::Form.new(@post)
105
-
redirect_to @post, notice:'Post updated!'
106
-
else
107
-
render :edit, status::unprocessable_entity
108
-
end
109
-
end
102
+
# ... other actions ...
110
103
end
111
104
```
112
105
@@ -145,7 +138,7 @@ end
145
138
Superform was built from the ground-up using Phlex components, which means you'll feel right at home using it with your existing Phlex views and components.
146
139
147
140
```ruby
148
-
classPosts::Form < Components::Form
141
+
classViews::Posts::Form < Components::Form
149
142
defview_template
150
143
div(class: "form-section") do
151
144
h2 { "Post Details" }
@@ -438,11 +431,12 @@ Superform eliminates the need to manually define strong parameters. Just include
438
431
```ruby
439
432
classPostsController < ApplicationController
440
433
includeSuperform::Rails::StrongParameters
434
+
includeViews::Posts
441
435
442
436
# Standard Rails CRUD with automatic strong parameters
443
437
defcreate
444
438
@post=Post.new
445
-
if save Posts::Form.new(@post)
439
+
if save Form.new(@post)
446
440
redirect_to @post, notice:'Post created successfully.'
447
441
else
448
442
render :new, status::unprocessable_entity
@@ -451,7 +445,7 @@ class PostsController < ApplicationController
0 commit comments