Skip to content

Instantly share code, notes, and snippets.

@h-sakano
Created October 7, 2017 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h-sakano/27b2fb2a660ab2bc26b376fd3563c90f to your computer and use it in GitHub Desktop.
Save h-sakano/27b2fb2a660ab2bc26b376fd3563c90f to your computer and use it in GitHub Desktop.
デフォルト値が設定されているモデルのreject_ifの指定方法 ref: http://qiita.com/h-sakano/items/06c11c9208e62e69491a
has_many :users
accepts_nested_attributes_for :users, reject_if: :all_blank
has_many :users
accepts_nested_attributes_for :users, reject_if: :reject_user
# デフォルト値が設定されているカラム以外が全て空ならreject
def reject_user(attributes)
attributes.except(:デフォルト値が設定されているカラム名).values.all?(&:blank?)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment