Skip to content

Instantly share code, notes, and snippets.

@ksol
Created July 15, 2012 14:52
Show Gist options
  • Select an option

  • Save ksol/3117277 to your computer and use it in GitHub Desktop.

Select an option

Save ksol/3117277 to your computer and use it in GitHub Desktop.
with_options demo
## 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