simple_form_object 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -8
- data/lib/simple_form_object/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c5b1bb8877957e9dece06a0ea28f2eddb48c744
|
4
|
+
data.tar.gz: b1d5870ddc177dad61b1ec5f313f37a378cb2565
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5cbbbde1b4d58ed0374267535412fb76375e172dd2ec02f16692357dab90844a2cc697a676b16d85235365fa0075c9c70ca80331dc115db70175b9ec326bb389
|
7
|
+
data.tar.gz: 97b625f72a2bdec29e3e97d2aabeb3364d6a33e47d0f1751fdd5e1015ed0d6f6d4a06dfc7f39ffab8c4a76847e62d28b7d4eb7eac8f04c9546ccd83eafa411cf
|
data/README.md
CHANGED
@@ -1,28 +1,72 @@
|
|
1
|
-
#
|
1
|
+
# SimpleFormObject
|
2
2
|
|
3
|
-
|
3
|
+
Allows you to make really simple non-persisted form objects or models.
|
4
|
+
|
5
|
+
**Only suitable for Rails 4 applications.**
|
6
|
+
|
7
|
+
You don't need to remember to:
|
8
|
+
|
9
|
+
1. `include ActiveModel::Model`
|
10
|
+
2. Set the class `model_name` so Rails url generation works for forms.
|
11
|
+
|
12
|
+
It gives you:
|
13
|
+
|
14
|
+
1. Default values for your form attributes.
|
15
|
+
2. Integration with simple_form so you don't need to specify the field type on the form.
|
16
|
+
3. Thanks to `ActiveModel::Model` you can use standard Rails validations on your attributes.
|
4
17
|
|
5
18
|
## Installation
|
6
19
|
|
7
20
|
Add this line to your application's Gemfile:
|
8
21
|
|
9
|
-
|
22
|
+
```ruby
|
23
|
+
gem 'simple_form_object'
|
24
|
+
```
|
10
25
|
|
11
26
|
And then execute:
|
12
27
|
|
13
28
|
$ bundle
|
14
29
|
|
15
|
-
|
30
|
+
## Usage
|
16
31
|
|
17
|
-
|
32
|
+
Create a form class. I like to put them inside `app/forms/`. If you
|
33
|
+
prefer to create models then that will work too.
|
18
34
|
|
19
|
-
|
35
|
+
```ruby
|
36
|
+
class PostForm
|
37
|
+
include SimpleFormObject
|
38
|
+
|
39
|
+
attribute :body, :text
|
40
|
+
attribute :title, :string
|
41
|
+
attribute :publish_date, :datetime, default: Time.now
|
42
|
+
|
43
|
+
validates_presence_of :body
|
44
|
+
validates_presence_of :title
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
`SimpleFormObject` includes `ActiveModel::Model` so you don't need to.
|
49
|
+
It also intelligently sets the `model_name` on the class so that Rails
|
50
|
+
routing works as expected. As an example:
|
51
|
+
|
52
|
+
```erb
|
53
|
+
<%= simple_form_for @post_form do |f| %>
|
54
|
+
<%= f.input :title # renders a simple string input %>
|
55
|
+
<%= f.input :body # renders a textarea %>
|
56
|
+
<%= f.input :publish_date # renders a datetime select html element %>
|
57
|
+
<% end %>
|
58
|
+
```
|
59
|
+
|
60
|
+
Will create a HTML form which will `POST` to `posts_path`.
|
61
|
+
|
62
|
+
## Todo:
|
20
63
|
|
21
|
-
|
64
|
+
1. Automatically add good validations for types.
|
65
|
+
2. It's tested in `spec` but better tests wouldn't hurt.
|
22
66
|
|
23
67
|
## Contributing
|
24
68
|
|
25
|
-
1. Fork it ( http://github.com
|
69
|
+
1. Fork it ( http://github.com/reInteractive-open/simple_form_objects/fork )
|
26
70
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
71
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
72
|
4. Push to the branch (`git push origin my-new-feature`)
|