strong_form 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a142d6706f992c0fcb09958dd322c770b044add9
4
- data.tar.gz: 8033a1ecbb67f7a1e30712989d388c73aa524fa3
3
+ metadata.gz: 3a9441ee5ebf5e65f21e6f9ad3089a71d37bf394
4
+ data.tar.gz: 6a22f5bd9548bf627225aeb4d7855a91f99b1e26
5
5
  SHA512:
6
- metadata.gz: cb54f2def3c884fee11af8abdd64de0b5af29c1e53603c3370b1065bb4d0f3a4f235790446c475e93edf50f9c737f8f9c855457c8f6db898bb59895242da64b5
7
- data.tar.gz: b92c0174c94f705096868102d8059e6830b501d0ce53a15cb4d65f9f1c6366749627d0a986a8286757a09a9561c9d246326f3d073e5fc143bc9e303579c94699
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
- require 'rake/testtask'
20
-
21
- Rake::TestTask.new(:test) do |t|
22
- t.libs << 'lib'
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: :test
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(association, options = {}, &block)
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)
@@ -1,3 +1,3 @@
1
1
  module StrongForm
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
@@ -3,5 +3,8 @@
3
3
 
4
4
  = f.fields_for :addresses do |af|
5
5
  = render 'address_fields', f: af
6
- = f.link_to_add :addresses do
7
- Add
6
+ - if params[:inline_link_to_add]
7
+ = f.link_to_add 'Add', :addresses, bla: :blub
8
+ - else
9
+ = f.link_to_add :addresses, bla: :blub do
10
+ Add