Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Option :all_blank is not working correctly when accepts_nested_attributes has option allow_destroy #2937

Closed
timotta opened this Issue Sep 8, 2011 · 3 comments

Comments

Projects
None yet
4 participants

timotta commented Sep 8, 2011

Reproducing the error:

Put in your model:

accepts_nested_attributes_for :enderecos,
:reject_if => :all_blank, :allow_destroy => true

Put in your form:

f.check_box :_destroy


There is a workaround, but i think this is a bug.


The wokaround:

accepts_nested_attributes_for :enderecos,
:reject_if => :not_filled, :allow_destroy => true

def not_filled(args)
attrs
.select{|k,v|k!='_destroy'}
.each do |k,v|
return false unless v.blank?
end
return true
end

Further discussion on a fix for this is being done here: https://gist.github.com/rails/rails/pull/3340

@josevalim josevalim added a commit that referenced this issue Oct 17, 2011

@josevalim josevalim Merge pull request #3340 from surfacedamage/exclude_destroy_in_all_bl…
…ank_check

Exclude _destroy parameter in :all_blank check (issue #2937)
7511f97

@rahul100885 rahul100885 added a commit to rahul100885/rails that referenced this issue Oct 18, 2011

@rahul100885 Aaron Christy + rahul100885 Exclude _destroy parameter in :all_blank check (issue #2937) 93bf56f
Contributor

nashby commented Apr 8, 2012

closed by this commit 7511f97 /cc @arunagw

Member

arunagw commented Apr 8, 2012

Closing this as #3340 merged!

Thanks @nashby :-)

@arunagw arunagw closed this Apr 8, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment