Put observations at the owner level, rather than a specific garden

This commit is contained in:
Daniel O'Connor
2024-01-07 01:46:51 +00:00
parent a4cfb6086a
commit fca91a0a71
2 changed files with 54 additions and 0 deletions

View File

@@ -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

View File

@@ -98,6 +98,7 @@ Rails.application.routes.draw do
resources :plantings
resources :harvests
resources :posts
resources :weather_observations
resources :follows
get 'followers' => 'follows#followers'