You won't get that far, as "nil.path_ids" fails before that (line 157). 
Put a debugger in line 156 then run rails s --debugger, 
and run "curl -v -k -H d"Content-Type:application/json" https://foreman/api/hosts/nonexistenthost/puppetclasses" from somewhere else, even without the debugger you'll see you get all puppetclasses back.