Permalink
Browse files

add all_blank proc

  • Loading branch information...
1 parent 516faf0 commit bf5a422cdcfdd922c3a33423d1fa6cb04cbd0be0 @asanghi committed Jan 16, 2013
Showing with 4 additions and 1 deletion.
  1. +3 −0 lib/active_record/mass_assignment_security/nested_attributes.rb
  2. +1 −1 test/models/person.rb
@@ -4,6 +4,9 @@ module NestedAttributes
extend ActiveSupport::Concern
module ClassMethods
+
+ REJECT_ALL_BLANK_PROC = proc { |attributes| attributes.all? { |key, value| key == '_destroy' || value.blank? } }
+
def accepts_nested_attributes_for(*attr_names)
options = { :allow_destroy => false, :update_only => false }
options.update(attr_names.extract_options!)
View
@@ -70,7 +70,7 @@ class NestedPerson < ActiveRecord::Base
attr_accessible :best_friend_attributes, :best_friend_first_name, :as => :admin
has_one :best_friend, :class_name => 'NestedPerson', :foreign_key => :best_friend_id
- accepts_nested_attributes_for :best_friend, :update_only => true
+ accepts_nested_attributes_for :best_friend, :update_only => true, :reject_if => :all_blank
def comments=(new_comments)
raise RuntimeError

0 comments on commit bf5a422

Please sign in to comment.