diff --git a/app/controllers/crops_controller.rb b/app/controllers/crops_controller.rb index 8a76566d0..1d2927cf5 100644 --- a/app/controllers/crops_controller.rb +++ b/app/controllers/crops_controller.rb @@ -192,6 +192,7 @@ class CropsController < ApplicationController :parent_id, :perennial, :request_notes, :reason_for_rejection, :rejection_notes, + :description, :row_spacing, :spread, :height, :sowing_method, :sun_requirements, :growing_degree_days, scientific_names_attributes: %i(scientific_name _destroy id) diff --git a/app/models/concerns/open_farm_data.rb b/app/models/concerns/open_farm_data.rb index 5f1f07967..34573d742 100644 --- a/app/models/concerns/open_farm_data.rb +++ b/app/models/concerns/open_farm_data.rb @@ -19,10 +19,6 @@ module OpenFarmData fetch_attr('tags_array') end - def description - fetch_attr('description') - end - def common_names fetch_attr('common_names') end diff --git a/app/views/crops/_form.html.haml b/app/views/crops/_form.html.haml index 8797bfe81..5c5c3b33a 100644 --- a/app/views/crops/_form.html.haml +++ b/app/views/crops/_form.html.haml @@ -42,6 +42,7 @@ %span.help-block Living more than two years %h2 OpenFarm Data + = f.text_area :description, label: 'Description' = f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0 = f.number_field :spread, label: 'Spread (cm)', min: 0 = f.number_field :height, label: 'Height (cm)', min: 0 diff --git a/db/migrate/20251128200506_add_description_to_crops.rb b/db/migrate/20251128200506_add_description_to_crops.rb new file mode 100644 index 000000000..de88393d2 --- /dev/null +++ b/db/migrate/20251128200506_add_description_to_crops.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +class AddDescriptionToCrops < ActiveRecord::Migration[7.2] + # Temporary model to avoid validation issues + class Crop < ApplicationRecord + end + + def up + add_column :crops, :description, :text + + # Ensure the new column is available to the temporary model + Crop.reset_column_information + + Crop.find_each do |crop| + next if crop.openfarm_data.blank? + + description = crop.openfarm_data.dig('attributes', 'description') + crop.update_column(:description, description) if description.present? + end + end + + def down + remove_column :crops, :description + end +end