strong_form 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -0
- data/Rakefile +5 -8
- data/lib/strong_form/nested_form.rb +5 -2
- data/lib/strong_form/version.rb +1 -1
- data/spec/dummy/app/views/base/nested_form_gem.html.haml +5 -2
- data/spec/dummy/log/test.log +2970 -0
- data/spec/examples.txt +55 -52
- data/spec/features/strong_form_spec.rb +25 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a9441ee5ebf5e65f21e6f9ad3089a71d37bf394
|
4
|
+
data.tar.gz: 6a22f5bd9548bf627225aeb4d7855a91f99b1e26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e6f0b3c3378364d77e4cb997d6523fe6e612fffdcfd2386338423b53d631070ce0122ad6f1a970ee35e75d7fb1e7ac71e4fab1aa0783c81a4a61db0216dcfbf
|
7
|
+
data.tar.gz: 1a7a85c7d615da3b65696dc300217ed136f9365c74389be76ce1b5a394927dbf7daeb552953b7dbaf94db6bdbe4bf9a55488c52b87ebc4c5146314fb4a36048f
|
data/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
StrongForm
|
2
|
+
===
|
3
|
+
|
4
|
+
Let's assume you use [strong parameters](https://github.com/rails/strong_parameters)
|
5
|
+
and have this:
|
6
|
+
|
7
|
+
```
|
8
|
+
def user_attributes
|
9
|
+
params.require(:user).permit(:first_name, :last_name)
|
10
|
+
end
|
11
|
+
```
|
12
|
+
|
13
|
+
Then you can simply output your form with those permitted parameters:
|
14
|
+
|
15
|
+
```
|
16
|
+
form_for(@user, permitted_attributes: user_attributes) do |f|
|
17
|
+
f.text_field :first_name
|
18
|
+
f.text_field :last_name
|
19
|
+
f.text_field :internal_id
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
And this gem will automatically disable every field which is not allowed,
|
24
|
+
so the resulting html will be:
|
25
|
+
|
26
|
+
```
|
27
|
+
<form ...>
|
28
|
+
<!-- not disabled, since in permitted_attributes -->
|
29
|
+
<input type="text" name="user[first_name]"/>
|
30
|
+
<input type="text" name="user[last_name]"/>
|
31
|
+
|
32
|
+
<!-- disabled, since not in permitted_attributes -->
|
33
|
+
<input type="text" name="user[internal_id]" disabled/>
|
34
|
+
</form>
|
35
|
+
```
|
36
|
+
|
37
|
+
Makes it easy to reuse form partials for different permitted attributes / user
|
38
|
+
rights.
|
39
|
+
|
40
|
+
Installation
|
41
|
+
===
|
42
|
+
|
43
|
+
Add it to your Gemfile then run bundle to install it.
|
44
|
+
|
45
|
+
```
|
46
|
+
gem 'strong_form'
|
47
|
+
```
|
48
|
+
|
49
|
+
Now you can pass `permitted_attributes` to your forms:
|
50
|
+
|
51
|
+
```
|
52
|
+
form_for @user, permitted_attributes: [:first_name, :last_name, ...] {}
|
53
|
+
```
|
54
|
+
|
55
|
+
Nested Form gem support
|
56
|
+
===
|
57
|
+
|
58
|
+
StrongForm includes support for [nested_form](https://github.com/ryanb/nested_form)
|
59
|
+
and hides the `link_to_add` and `link_to_remove` if it is not possible to create
|
60
|
+
new or remove existing records.
|
61
|
+
|
62
|
+
Code Status
|
63
|
+
===
|
64
|
+
[![Build Status](https://travis-ci.org/Stellenticket/strong_form.svg?branch=master)](https://travis-ci.org/Stellenticket/strong_form)
|
65
|
+
|
66
|
+
ToDo
|
67
|
+
===
|
68
|
+
|
69
|
+
* Allow to skip field output instead of disabling it
|
70
|
+
* Allow to manually set replacement for a disabled field
|
data/Rakefile
CHANGED
@@ -16,13 +16,10 @@ end
|
|
16
16
|
|
17
17
|
Bundler::GemHelper.install_tasks
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
t.libs << 'test'
|
24
|
-
t.pattern = 'test/**/*_test.rb'
|
25
|
-
t.verbose = false
|
19
|
+
begin
|
20
|
+
require 'rspec/core/rake_task'
|
21
|
+
RSpec::Core::RakeTask.new(:spec)
|
22
|
+
rescue LoadError
|
26
23
|
end
|
27
24
|
|
28
|
-
task default: :
|
25
|
+
task default: :spec
|
@@ -3,7 +3,10 @@ module NestedForm
|
|
3
3
|
alias_method :orig_link_to_add, :link_to_add
|
4
4
|
alias_method :orig_link_to_remove, :link_to_remove
|
5
5
|
|
6
|
-
def link_to_add(
|
6
|
+
def link_to_add(*args, &block)
|
7
|
+
options = args.extract_options!.symbolize_keys
|
8
|
+
association = args.pop
|
9
|
+
|
7
10
|
if object.respond_to?(:permitted_attributes)
|
8
11
|
return unless object.permitted_nested_attributes?(association)
|
9
12
|
|
@@ -24,7 +27,7 @@ module NestedForm
|
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
orig_link_to_add(association, options, &block)
|
30
|
+
orig_link_to_add(*args, association, options, &block)
|
28
31
|
end
|
29
32
|
|
30
33
|
def link_to_remove(*args, &block)
|
data/lib/strong_form/version.rb
CHANGED