-
-
Save cpruitt/ec1a9095020ea042b735b2ba760a8a5d to your computer and use it in GitHub Desktop.
Reject based on deep nested blank attributes
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
| class Answer < ApplicationRecord | |
| has_one :answer_open, dependent: :destroy | |
| has_one :answer_rating, dependent: :destroy | |
| accepts_nested_attributes_for :answer_open, reject_if: :all_blank | |
| accepts_nested_attributes_for :answer_rating, reject_if: :all_blank | |
| end |
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
| class Submission < ApplicationRecord | |
| has_many :answers, dependent: :destroy | |
| accepts_nested_attributes_for :answers, reject_if: proc { |attributes| | |
| answer_open_attrs = attributes["answer_open_attributes"] | |
| return false unless answer_open_attrs && answer_open_attrs["response"] | |
| true | |
| } | |
| # REJECT ANSWER IF ASSOCIATED ANSWER_TYPE IS BLANK | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment