Files
growstuff/app/controllers/charts/gardens_controller.rb
Brenda 17f5b1c562 Routes using slugs (instead of ids)
this seems to be intended by the models having slugs (added about 7 years ago) but the routes weren't using them
2020-01-10 16:50:52 +13:00

19 lines
582 B
Ruby

# frozen_string_literal: true
module Charts
class GardensController < ApplicationController
respond_to :json
def timeline
@data = []
@garden = Garden.find(params[:garden_slug])
@garden.plantings.where.not(planted_at: nil)
.order(finished_at: :desc).each do |p|
# use finished_at if we have it, otherwise use predictions
finish = p.finished_at.presence || p.finish_predicted_at || Time.zone.today.to_date
@data << [p.crop.name, p.planted_at, finish] if finish.present?
end
render json: @data
end
end
end