From fca91a0a71aa87ce19db992e98d42e23bc4ffdb4 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 7 Jan 2024 01:46:51 +0000 Subject: [PATCH] Put observations at the owner level, rather than a specific garden --- .../weather_observations_controller.rb | 53 +++++++++++++++++++ config/routes.rb | 1 + 2 files changed, 54 insertions(+) create mode 100644 app/controllers/weather_observations_controller.rb diff --git a/app/controllers/weather_observations_controller.rb b/app/controllers/weather_observations_controller.rb new file mode 100644 index 000000000..9b7ef4424 --- /dev/null +++ b/app/controllers/weather_observations_controller.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +class WeatherObservationsController < DataController + def index + @owner = Member.find_by(slug: params[:member_slug]) + @show_all = params[:all] == '1' + @show_jump_to = params[:member_slug].present? ? true : false + + # @weather_observations = @weather_observations.includes(:owner) + # @weather_observations = @weather_observations.active unless @show_all + # @weather_observations = @weather_observations.where(owner: @owner) if @owner.present? + # @weather_observations = @weather_observations.where.not(members: { confirmed_at: nil }) + # .order(:name).paginate(page: params[:page]) + respond_with(@weather_observations) + end + + def show + respond_with(@weather_observation) + end + + def new + @weather_observation = WeatherObservation.new + respond_with(@weather_observation) + end + + def edit + respond_with(@weather_observation) + end + + def create + @weather_observation.owner_id = current_member.id + flash[:notice] = I18n.t('weather_observations.created') if @weather_observation.save + respond_with(@weather_observation) + end + + def update + flash[:notice] = I18n.t('weather_observations.updated') if @weather_observation.update(weather_observation_params) + respond_with(@weather_observation) + end + + def destroy + @weather_observation.destroy + flash[:notice] = I18n.t('weather_observations.deleted') + redirect_to(member_weather_observations_path(@weather_observation.owner)) + end + + private + + def weather_observation_params + params.require(:weather_observation).permit! + end + end + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index e21ada9be..55c30e341 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -98,6 +98,7 @@ Rails.application.routes.draw do resources :plantings resources :harvests resources :posts + resources :weather_observations resources :follows get 'followers' => 'follows#followers'