Last active
July 10, 2017 04:00
-
-
Save adavia/4208c0d71b28bc942f254c4e02ca6b63 to your computer and use it in GitHub Desktop.
Parse errors
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
| def parse_errors | |
| { | |
| errors: { | |
| questions: @post.questions.enum_for(:each_with_index).collect { |question, index| | |
| { | |
| index => question.errors.messages | |
| } unless question.valid? | |
| }.inject({}, :merge).transform_values {|v| v.transform_values &:first } | |
| }.merge!(@post.errors.messages) | |
| } | |
| end | |
| # get {:errors=>{:questions=>{0=>{:title=>"can't be blank"}, 1=>{:title=>"can't be blank"}}, :"questions.title"=>["can't be blank"], :title=>["can't be blank"]}} | |
| # expect {:errors=>{:questions=>{0=>{:title=>"can't be blank"}, 1=>{:title=>"can't be blank"}}, :title=>["can't be blank"]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment