class MetricSnapshotsController < ApplicationController
  def index
    respond_to do |format|
      format.json { render json: {metric_snapshots: MetricSnapshot.all} }
    end
  end

  def show
    if set_metric_snapshot
      respond_to do |format|
        format.json { render json: {metric_snapshot: @metric_snapshot}, status: :ok }
      end
    end
  end

  def metric_configuration
    if set_metric_snapshot
      respond_to do |format|
        format.json { render json: {metric_configuration: @metric_snapshot.metric_configuration}, status: :ok }
      end
    end
  end

  private

  def set_metric_snapshot
    begin
      @metric_snapshot = MetricSnapshot.find(params[:id].to_i)
      true
    rescue ActiveRecord::RecordNotFound => exception
      respond_to do |format|
        format.json { render json: {errors: [exception.message]}, status: :not_found }
      end
      false
    end
  end
end

class MetricSnapshotsController < ApplicationController
  def index
    respond_with_json metric_snapshots: MetricSnapshot.all
  end

  def show
    respond_with_json(metric_snapshot: @metric_snapshot) if set_metric_snapshot
  end

  def metric_configuration
    respond_with_json(metric_configuration: @metric_snapshot.metric_configuration) if set_metric_snapshot
  end

  private

  def set_metric_snapshot
    begin
      @metric_snapshot = MetricSnapshot.find(params[:id].to_i)
      true
    rescue ActiveRecord::RecordNotFound => exception
      respond_with_json({ errors: [exception.message]}, :not_found)
      false
    end
  end
end

Use respond_with_json on metric snapshots controller
Use respond_with_json on metric snapshots controller
