Why are we checking if apps and parent_app exist, when its explicitly stated above?  Also, an empty array is not falsey, so you need to check if its empty, not just use its 'boolean-equivalent'

Bad: if apps && ...
Good: if apps.empty? && ...
Even better: no conditional because it was set above and could not have changed :)