How do I reject the creation of an object if all of the attributes are
blank?
accepts_nested_attributes_for :questions, :allow_destroy =>
true, :reject_if => lambda {|a| a.each.blank? }
How do I reject the creation of an object if all of the attributes are
blank?
accepts_nested_attributes_for :questions, :allow_destroy =>
true, :reject_if => lambda {|a| a.each.blank? }
You can do like this using all? method
accepts_nested_attributes_for :questions, :allow_destroy => true,
:reject_if => lambda { |attrs| attrs.all? { |k, v| v.blank?}}
–
Thanks,
Abhinav
http://twitter.com/abhinav
that works, thanks!
Does that still reject the object if the id attribute is not blank?
Do I have to test each attribute separately and exclude the id
attribute in order for that to work?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs