Created
July 15, 2012 14:52
-
-
Save ksol/3117277 to your computer and use it in GitHub Desktop.
with_options demo
This file contains hidden or 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
| ## Classic | |
| accepts_nested_attributes_for :addresses, reject_if: :all_blank, allow_destroy: true | |
| accepts_nested_attributes_for :client_detail, reject_if: :all_blank, allow_destroy: true | |
| ## with_options | |
| with_options reject_if: :all_blank, allow_destroy: true do |u| | |
| u.accepts_nested_attributes_for :addresses | |
| u.accepts_nested_attributes_for :client_detail | |
| end | |
| ## If the last arg is a hash, the options are merged into said hash | |
| with_options presence: true do |u| | |
| u.validates :name | |
| u.validates :client_detail, if: :client? | |
| u.validates :specialist_detail, if: :specialist? | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment