<commit_before>class BiodiversityReportsController < ApplicationController
  before_action :login_required
  before_action :load_plots_and_plants, only: [:new, :edit]
  before_action :set_biodiversity_report, only: [:show, :edit, :update, :destroy]

  def index
    @biodiversity_reports = BiodiversityReport.all
  end

  def show
  end

  def new
    @biodiversity_report = BiodiversityReport.new
    @biodiversity_report.plant_samples.build
    @biodiversity_report.build_soil_sample
  end

  def edit
  end

  def create
    @biodiversity_report = BiodiversityReport.new(biodiversity_report_params)
    @current_user.biodiversity_reports << @biodiversity_report
    if @biodiversity_report.save
      redirect_to biodiversity_reports_path
      flash[:success] = 'Biodiversity report was successfully created.'
    else
      load_plots_and_plants
      render :new
    end
  end

  def update
    @biodiversity_report = BiodiversityReport.find(params[:id])
    if @biodiversity_report.update(biodiversity_report_params)
      redirect_to @biodiversity_report
      flash[:success] = 'Biodiversity report was successfully updated.'
    else
      load_plots_and_plants
      render :edit
    end
  end

  def destroy
    @biodiversity_report = BiodiversityReport.find(params[:id])
    @biodiversity_report.destroy
    redirect_to biodiversity_reports_path
    flash[:success] = 'Biodiversity report was successfully destroyed.'
  end

  private

  def load_plots_and_plants
    @plots = Plot.all
    @plants = Plant.all
  end

  def set_biodiversity_report
    @biodiversity_report = BiodiversityReport.find(params[:id])
  end

  def biodiversity_report_params
    params.require(:biodiversity_report).permit(:date, :time, :temperature,
      :biomass_estimate, :species_richness, :photo, :plot_id,
      plant_samples_attributes: [:plant_id, :biodiversity_report_id, :abundance,
        :percent_cover, :biomass_estimate, :photo, :_destroy, :id],
      soil_sample_attributes: [:ph_level, :temperature, :biodiversity_report_id, :_destroy, :id])
  end

end<commit_msg>BiodiversityReportsController: Update allowable params. I forgot to change :date and :time to :measured_on and :measured_at. See b6b3f518b5c8ca51901d6f0ea63b49621fafa0e0. References #38, #60.<commit_after>class BiodiversityReportsController < ApplicationController
  before_action :login_required
  before_action :load_plots_and_plants, only: [:new, :edit]
  before_action :set_biodiversity_report, only: [:show, :edit, :update, :destroy]

  def index
    @biodiversity_reports = BiodiversityReport.all
  end

  def show
  end

  def new
    @biodiversity_report = BiodiversityReport.new
    @biodiversity_report.plant_samples.build
    @biodiversity_report.build_soil_sample
  end

  def edit
  end

  def create
    @biodiversity_report = BiodiversityReport.new(biodiversity_report_params)
    @current_user.biodiversity_reports << @biodiversity_report
    if @biodiversity_report.save
      redirect_to biodiversity_reports_path
      flash[:success] = 'Biodiversity report was successfully created.'
    else
      load_plots_and_plants
      render :new
    end
  end

  def update
    @biodiversity_report = BiodiversityReport.find(params[:id])
    if @biodiversity_report.update(biodiversity_report_params)
      redirect_to @biodiversity_report
      flash[:success] = 'Biodiversity report was successfully updated.'
    else
      load_plots_and_plants
      render :edit
    end
  end

  def destroy
    @biodiversity_report = BiodiversityReport.find(params[:id])
    @biodiversity_report.destroy
    redirect_to biodiversity_reports_path
    flash[:success] = 'Biodiversity report was successfully destroyed.'
  end

  private

  def load_plots_and_plants
    @plots = Plot.all
    @plants = Plant.all
  end

  def set_biodiversity_report
    @biodiversity_report = BiodiversityReport.find(params[:id])
  end

  def biodiversity_report_params
    params.require(:biodiversity_report).permit(:measured_on, :measured_at, :temperature,
      :biomass_estimate, :species_richness, :photo, :plot_id,
      plant_samples_attributes: [:plant_id, :biodiversity_report_id, :abundance,
        :percent_cover, :biomass_estimate, :photo, :_destroy, :id],
      soil_sample_attributes: [:ph_level, :temperature, :biodiversity_report_id, :_destroy, :id])
  end

end
{'fraction_non_alphanumeric': 0.07660359944623904, 'fraction_numerical': 0.006229810798338717, 'mean_word_length': 4.529336734693878, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '820018', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1352, 'n_words': 278}