ruby/ddl/app/controllers/metric_controller.rb
def update
    # Modifies an existing metric.
    metric = Metric.where(id: update_params[:metric_id]).includes(:account).first
    unless metric
      return render status: 404, json: {error: "Unable to find metric to update with id #{update_params[:metric_id]}"}
    end

    unless metric.account.id.to_s == update_params[:account_id].to_s
      return render status: 404, json: {error: "Unable to find account with id #{update_params[:account_id]}"}
    end

    [:name, :desc].each do |key|
      metric[key] = update_params[key] if update_params.has_key?(key)
    end

    if metric.save
      render status: 200, json: metric
    else
      render status: 400, json: {error: metric.errors}
    end
  end
# Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them .
def update
    metric = Metric.where(id: update_params[:metric_id]).includes(:account).first
    unless metric
      return render status: 404, json: {error: "Unable to find metric to update with id #{update_params[:metric_id]}"}
    end
    unless metric.account.id.to_s == update_params[:account_id].to_s
      return render status: 404, json: {error: "Unable to find account with id #{update_params[:account_id]}"}
    end
    [:name, :desc].each do |key|
      metric[key] = update_params[key] if update_params.has_key?(key)
    end
    if metric.save
      render status: 200, json: metric
    else
      render status: 400, json: {error: metric.errors}
    end
  end
def update metric = Metric . where ( id : update_params [ :metric_id ] ) . includes ( :account ) . first unless metric return render status : 404 , json : { error : "Unable to find metric to update with id #{update_params[:metric_id]}" } end unless metric . account . id . to_s == update_params [ :account_id ] . to_s return render status : 404 , json : { error : "Unable to find account with id #{update_params[:account_id]}" } end [ :name , :desc ] . each do | key | metric [ key ] = update_params [ key ] if update_params . has_key? ( key ) end if metric . save render status : 200 , json : metric else render status : 400 , json : { error : metric . errors } end end
Handles the API for creating metrics and posting data to them.
Handles the API for creating metrics and posting data to them .
# Modifies an existing metric.