Code Review

Not sure why you need the `to_json.html_safe` here - can't you just `render json`?

It looks like you are trying to customize the json (particularly in regards to nested objects).  You can [customize what `to_json` includes](http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html) by passing an options hash.  There are also gems, such as [ActiveModel Serializers](https://github.com/rails-api/active_model_serializers) that allow you to specify different ways of generating json from the same object.