Skip to content

Instantly share code, notes, and snippets.

@zzak
Created June 13, 2014 21:55
Show Gist options
  • Save zzak/7d4705a7c0458039b00e to your computer and use it in GitHub Desktop.
Save zzak/7d4705a7c0458039b00e to your computer and use it in GitHub Desktop.
diff --git a/lib/active_record/mass_assignment_security/associations.rb b/lib/active_record/mass_assignment_security/associations.rb
index ade4d3a..e6b23a9 100644
--- a/lib/active_record/mass_assignment_security/associations.rb
+++ b/lib/active_record/mass_assignment_security/associations.rb
@@ -84,6 +84,18 @@ module ActiveRecord
end
private :build_record
+
+ def build_through_record(record)
+ build_through_record_without_protection(record)
+ end
+
+ def build_through_record_without_protection(record)
+ ensure_mutable
+
+ through_record = through_association.build through_scope_attributes, without_protection: true
+ through_record.send("#{source_reflection.name}=", record)
+ through_record
+ end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment