hash_to_hidden_fields 1.0.0 → 2.0.0
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.
data/README.md
CHANGED
@@ -4,13 +4,13 @@ Sometimes in your Rails app you want a user to begin an action, log in, then com
|
|
4
4
|
|
5
5
|
Add this to your Gemfile:
|
6
6
|
|
7
|
-
```ruby
|
7
|
+
``` ruby
|
8
8
|
gem "hash_to_hidden_fields"
|
9
9
|
```
|
10
10
|
|
11
11
|
Filter the params you want to save and turn them into hidden fields in your form:
|
12
12
|
|
13
|
-
```erb
|
13
|
+
``` erb
|
14
14
|
<%= hash_to_hidden_fields(@params_to_save) %>
|
15
15
|
```
|
16
16
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/core_ext/object/to_query'
|
1
2
|
require 'action_view'
|
2
3
|
require 'action_view/helpers'
|
3
4
|
|
@@ -5,8 +6,8 @@ module ActionView
|
|
5
6
|
module Helpers
|
6
7
|
module HashToHiddenFields
|
7
8
|
def hash_to_hidden_fields(hash)
|
8
|
-
|
9
|
-
pairs =
|
9
|
+
cleaned_hash = hash.reject { |k, v| v.nil? }
|
10
|
+
pairs = cleaned_hash.to_query.split(Rack::Utils::DEFAULT_SEP)
|
10
11
|
|
11
12
|
tags = pairs.map do |pair|
|
12
13
|
key, value = pair.split('=', 2).map { |str| Rack::Utils.unescape(str) }
|
@@ -17,4 +18,4 @@ module ActionView
|
|
17
18
|
end
|
18
19
|
end
|
19
20
|
end
|
20
|
-
end
|
21
|
+
end
|
@@ -8,8 +8,9 @@ test_hash = {
|
|
8
8
|
"nested1" => "3",
|
9
9
|
"nested2" => "4"
|
10
10
|
},
|
11
|
+
"nil" => nil,
|
11
12
|
"array" => [
|
12
|
-
|
13
|
+
1, 2, "3", "abc"
|
13
14
|
],
|
14
15
|
"array of hashes" => [
|
15
16
|
{ "key 1" => "val 1" },
|
@@ -56,4 +57,4 @@ describe ActionView::Base do
|
|
56
57
|
@hash_to_hidden_fields.size.should == expected_html_blocks.join("\n").size
|
57
58
|
end
|
58
59
|
end
|
59
|
-
end
|
60
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_to_hidden_fields
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
-
|
7
|
+
- 2
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
version:
|
10
|
+
version: 2.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brian Hempel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-22 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
requirements: []
|
113
113
|
|
114
114
|
rubyforge_project: hash_to_hidden_fields
|
115
|
-
rubygems_version: 1.8.
|
115
|
+
rubygems_version: 1.8.21
|
116
116
|
signing_key:
|
117
117
|
specification_version: 3
|
118
118
|
summary: In goes a hash, out comes hidden fields. Great for preserving Rails parameters without abusing the session.
|