<commit_before>class PlantsController < ApplicationController
  before_action :set_plant, only: [:show, :edit, :update, :destroy, :download_qr]
  before_action :login_required, only: [:new, :create, :edit, :update, :destroy]
  before_action :admin_required, only: [:new, :create, :edit, :update, :destroy]
  before_action :redirect_cancel_edit, :only => [:update]
  before_action :redirect_cancel_edit, :only => [:create]

  def index
    @plants = Plant.all
  end

  def show; end

  def new
    @plant = Plant.new
  end

  def edit; end

  def create
    @plant = Plant.new(plant_params)
    if @plant.save
      redirect_to plants_path # , {last_added_id: @plant.id }, then create view method
      flash[:success] = 'Plant was successfully created.'
    else
      render :new
    end
  end

  def update
    if @plant.update(plant_params)<commit_msg>add sort by plant common name to plant controller<commit_after>class PlantsController < ApplicationController
  before_action :set_plant, only: [:show, :edit, :update, :destroy, :download_qr]
  before_action :login_required, only: [:new, :create, :edit, :update, :destroy]
  before_action :admin_required, only: [:new, :create, :edit, :update, :destroy]
  before_action :redirect_cancel_edit, :only => [:update]
  before_action :redirect_cancel_edit, :only => [:create]

  def index
    @plants = Plant.all.sort_by {|plant| plant.common_name.downcase}
  end

  def show; end

  def new
    @plant = Plant.new
  end

  def edit; end

  def create
    @plant = Plant.new(plant_params)
    if @plant.save
      redirect_to plants_path # , {last_added_id: @plant.id }, then create view method
      flash[:success] = 'Plant was successfully created.'
    else
      render :new
    end
  end

  def update
    if @plant.update(plant_params)
{'fraction_non_alphanumeric': 0.11222780569514237, 'fraction_numerical': 0.0, 'mean_word_length': 3.923076923076923, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2870580', 'n_tokens_mistral': 592, 'n_tokens_neox': 572, 'n_words': 167}