<commit_before>class FlightsController < ApplicationController
  def index
  end

  def show
  end

  def new
    @pilot = Pilot.find_by(id: params[:pilot_id])
    if !can_edit?
      flash[:notice] = "You do not have permission to edit this page"
      redirect_to root_path
    else
      @flight = @pilot.flights.new
      @flight_airplanes = @flight.flight_airplanes.build
      @airplane = @flight_airplanes.build_airplane
    end
  end

  def create
    raise params.inspect
    @pilot = Pilot.find_by(id: params[:pilot_id])
    @flight = @pilot.log_books.first.flights.new(flight_params)
    if @flight.save
      redirect_to pilot_path(@flight.pilot)
    else
      raise @flight.inspect
    end
  end

  def edit
  end

  def update
  end

  def destroy
  end

  def flight_params
    params.require(:flight).permit(:date, :origin, :destination, :notes, :instructor, airplane: [:make, :model], flight_airplane: [:tail_number])
  end
end
<commit_msg>can create flight, without nested resources<commit_after>class FlightsController < ApplicationController
  def index
  end

  def show
  end

  def new
    @pilot = Pilot.find_by(id: params[:pilot_id])
    if !can_edit?
      flash[:notice] = "You do not have permission to edit this page"
      redirect_to root_path
    else
      @flight = @pilot.flights.new
      @flight_airplanes = @flight.flight_airplanes.build
      @airplane = @flight_airplanes.build_airplane
    end
  end

  def create
    @pilot = Pilot.find_by(id: params[:pilot_id])
    if can_edit?
      @flight = @pilot.log_books.first.flights.new(flight_params)
      if @flight.save
        redirect_to pilot_path(@flight.pilot)
      else
        raise @flight.inspect
      end
    else
      flash[:notice] = "You do not have permission to edit this page"
      redirect_to root_path
    end
  end

  def edit
  end

  def update
  end

  def destroy
  end

  def flight_params
    params.require(:flight).permit(:date, :origin, :destination, :notes, :instructor, flight_airplane_attributes: [:tail_number, airplane_attributes: [:make, :model]])
  end
end

{'fraction_non_alphanumeric': 0.08960229995208434, 'fraction_numerical': 0.0, 'mean_word_length': 3.1102362204724407, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1671873', 'n_tokens_mistral': 737, 'n_tokens_neox': 675, 'n_words': 175}