Created
October 7, 2017 14:19
-
-
Save h-sakano/27b2fb2a660ab2bc26b376fd3563c90f to your computer and use it in GitHub Desktop.
デフォルト値が設定されているモデルのreject_ifの指定方法 ref: http://qiita.com/h-sakano/items/06c11c9208e62e69491a
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
has_many :users | |
accepts_nested_attributes_for :users, reject_if: :all_blank |
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
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