Skip to content
This repository was archived by the owner on Aug 21, 2024. It is now read-only.

Commit 7567c9d

Browse files
committed
merge
2 parents 819baf7 + 6762ff9 commit 7567c9d

File tree

4 files changed

+21
-5
lines changed

4 files changed

+21
-5
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.2.3
2+
3+
* Fixed ArgumentError with nested attributes
4+
5+
## 1.2.2
6+
7+
* Fix for Rails 5
8+
9+
## 1.2.1
10+
11+
* Fix for Rails 5
12+
113
## 1.2.0
214

315
* Added Rails 5 support, already works just needed the gemspec updated to allow it

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![Build Status](https://api.travis-ci.org/westonganger/protected_attributes_continued.svg?branch=master)](https://travis-ci.org/westonganger/protected_attributes_continued)
44

5-
This is the community continued version of `protected_attributes`. I have created this new repo because the Rails team refuses to support the `protected_attributes` gem for Rails 5. It already works perfectly fine with Rails 5 it just needed the dependencies relaxed. For people who would like to continue using this feature in their Rails 5 apps lets continue the development here. The original `protected_attributes` was officially supported by the Rails team until the release of Rails 5.0.
5+
This is the community continued version of `protected_attributes`. I have created this new repo and changed the name because the Rails team refuses to support the `protected_attributes` gem for Rails 5. For people who would like to continue using this feature in their Rails 5 apps lets continue here. I am currently_using this successfully in number of Rails 5 production apps.
66

77
Protect attributes from mass-assignment in Active Record models.
88

lib/active_record/mass_assignment_security/nested_attributes.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ def assign_nested_attributes_for_one_to_one_association(association_name, attrib
7676
def assign_nested_attributes_for_collection_association(association_name, attributes_collection, assignment_opts = {})
7777
options = self.nested_attributes_options[association_name]
7878

79-
unless attributes_collection.is_a?(Hash) || attributes_collection.is_a?(Array)
80-
raise ArgumentError, "Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
79+
class_name = attributes_collection.class.name
80+
81+
if class_name == 'ActionController::Parameters'
82+
attributes_collection = attributes_collection.to_unsafe_h
83+
elsif !['Hash','Array'].include?(class_name)
84+
raise ArgumentError, "ActionController::Parameters or Hash or Array expected, got #{attributes_collection.class.name} (#{attributes_collection.inspect})"
8185
end
8286

8387
if limit = options[:limit]
@@ -109,7 +113,7 @@ def assign_nested_attributes_for_collection_association(association_name, attrib
109113
existing_records = if association.loaded?
110114
association.target
111115
else
112-
attribute_ids = attributes_collection.map {|a| a['id'] || a[:id] }.compact
116+
attribute_ids = attributes_collection.map{|a| a['id'] || a[:id] }.compact
113117
attribute_ids.empty? ? [] : association.scope.where(association.klass.primary_key => attribute_ids)
114118
end
115119

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ProtectedAttributes
2-
VERSION = "1.2.2"
2+
VERSION = "1.2.3"
33
end

0 commit comments

Comments
 (0)