mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-26 10:45:04 -04:00
This change adds the ability for crop wranglers to create and manage companion plantings for crops. - Adds a `source_url` to the `CropCompanion` model to store an optional reference URL. - Restricts the management of companion plantings to users with the `crop_wrangler` role. - Creates a new admin interface for managing companion plantings for a specific crop. - Updates the crop show page to display companions from both the crop and its parent crop.
41 lines
975 B
Ruby
41 lines
975 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Admin
|
|
class CropCompanionsController < AdminController
|
|
before_action :set_crop
|
|
|
|
def index
|
|
@crop_companions = @crop.crop_companions
|
|
end
|
|
|
|
def new
|
|
@crop_companion = @crop.crop_companions.new
|
|
end
|
|
|
|
def create
|
|
@crop_companion = @crop.crop_companions.new(crop_companion_params)
|
|
if @crop_companion.save
|
|
redirect_to admin_crop_crop_companions_path(@crop), notice: 'Companion was successfully created.'
|
|
else
|
|
render :new
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@crop_companion = @crop.crop_companions.find(params[:id])
|
|
@crop_companion.destroy
|
|
redirect_to admin_crop_crop_companions_path(@crop), notice: 'Companion was successfully destroyed.'
|
|
end
|
|
|
|
private
|
|
|
|
def set_crop
|
|
@crop = Crop.find_by!(slug: params[:crop_slug])
|
|
end
|
|
|
|
def crop_companion_params
|
|
params.require(:crop_companion).permit(:crop_b_id, :source_url)
|
|
end
|
|
end
|
|
end
|