Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow you to pass :all_blank to :reject_if option to automatically cr…
…eate a Proc that will reject any record with blank attributes.
- Loading branch information
Showing
4 changed files
with
30 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9010ed2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's pretty typical to end up with something like this
"choices_attributes"=>{"0"=>{"upperlimit"=>"", "_delete"=>"0", "lowerlimit"=>"", "value"=>""}}
which will fail the :all_blank test since _delete => 0
maybe all except hidden field should be blank? (detecting hiddenness by the _? - ugh)
9010ed2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well you could do
proc { |attributes| attributes.reject {|k,v| k == '_delete'}.all? {|k,v| v.blank?} }
9010ed2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if you follow this convention you shouldn't have a problem
9010ed2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this feature... Any reason why this haven't made it into 2-3-stable yet?
9010ed2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the following:
lambda { |attrs| attrs.all? { |k,v| k == '_delete' || v.blank? } }
It uses lambda, instead of proc, which has a different meaning in ruby 1.9
I don't like to have the new_record? check in my views. Why is that necessary?