Skip to content

Commit 00f0562

Browse files
authored
Merge pull request #34 from ediathome/main
Add Upload fields example to docs
2 parents 3e79cdd + e5d6d29 commit 00f0562

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,24 @@ class SignupForm < ApplicationForm
251251
end
252252
```
253253

254+
### Upload fields
255+
If you want to add file upload fields to your form you will need to initialize your form with the `enctype` attribute set to `multipart/form-data` as shown in the following example code:
256+
257+
```ruby
258+
class User::ImageForm < ApplicationForm
259+
def template
260+
# render label
261+
render field(:image).input(type: "file").label { "Choose file" }
262+
# render file input with accept attribute for png and jpeg images
263+
render field(:image).input(type: "file", accept: "image/png, image/jpeg")
264+
end
265+
end
266+
267+
# IMPORTANT
268+
# When rendering the form remember to init the User::ImageForm like that
269+
render User::ImageForm.new(@usermodel, enctype: "multipart/form-data")
270+
```
271+
254272

255273
## Extending Superforms
256274

0 commit comments

Comments
 (0)