rails / protected_attributes

Protect attributes from mass-assignment in ActiveRecord models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

using accepts_nested_attributes_for with reject_if and all_blank raises error

asanghi opened this issue · comments

Using this

accepts_nested_attribtues_for :addresses, allow_destroy: true, reject_if: :all_blank

raises ->

uninitialized constant ActiveRecord::MassAssignmentSecurity::NestedAttributes::ClassMethods::REJECT_ALL_BLANK_PROC

@asanghi it's because it is in a different lexical scope now ActiveRecord::NestedAttributes::ClassMethods versus ActiveRecord::MassAssignmentSecurity::NestedAttributes::ClassMethods. Can you come up with a PR to fix this? I think we just need to alias the constant in the correct lexical scope, e.g:

module ActiveRecord
  module MassAssignmentSecurity
    module NestedAttributes
      module ClassMethods
        REJECT_ALL_BLANK_PROC = ::ActiveRecord::NestedAttributes::ClassMethods::REJECT_ALL_BLANK_PROC
      end
    end
  end
end

Is there failing test for this already? If not can you add one for :all_blank option - thanks!

👍 also ran into this issue.