Suppose I have a Rails application with two models Postand Comment. Comments has_manyand comment belongs_topost.
How can I override a function respond_toin action showto get a JSON response containing both properties Postand an array of objects Commentthat it has?
This value is currently used for vanilla rails:
def show
@post = current_user.posts.find(params[:id])
respond_to do |format|
format.html
format.json { render json: @post }
end
end
source
share