title: How to solve NoMethodError for this case?
body: <p>So my rails app has a number of airport fares defined for each operator, as:</p>
  
  <pre><code>class AirportFare &lt; ActiveRecord::Base
      belongs_to :operator
  end
  
  class Operator &lt; ActiveRecord::Base
      has_many :airport_fares
  end
  </code></pre>
  
  <p>My routes are defined as:</p>
  
  <pre><code>resources :operators do
      resources :airport_fares
  end
  </code></pre>
  
  <p>And following is my airport_fares_controller:</p>
  
  <pre><code>class AirportFaresController &lt; ApplicationController
    before_action :set_airport_fare, only: [:show, :edit, :update, :destroy]
    before_action :set_operator
  
    # GET /airport_fares
    # GET /airport_fares.json
    def index
      @operator = Operator.find(params[:operator_id])
      @airport_fares = Operator.find(params[:operator_id]).airport_fares
    end
  
    # GET /airport_fares/1
    # GET /airport_fares/1.json
    def show
    end
  
    # GET /airport_fares/new
    def new
      @airport_fare = Operator.find(params[:operator_id]).airport_fares.build
    end
  
    # GET /airport_fares/1/edit
    def edit
    end
  
    # POST /airport_fares
    # POST /airport_fares.json
    def create
      @airport_fare = Operator.find(params[:operator_id]).airport_fares.build(airport_fare_params)
  
      respond_to do |format|
        if @airport_fare.save
          format.html { redirect_to @airport_fare, notice: 'Airport fare was successfully created.' }
          format.json { render :show, status: :created, location: @airport_fare }
        else
          format.html { render :new }
          format.json { render json: @airport_fare.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /airport_fares/1
    # PATCH/PUT /airport_fares/1.json
    def update
      respond_to do |format|
        if @airport_fare.update(airport_fare_params)
          format.html { redirect_to @airport_fare, notice: 'Airport fare was successfully updated.' }
          format.json { render :show, status: :ok, location: @airport_fare }
        else
          format.html { render :edit }
          format.json { render json: @airport_fare.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /airport_fares/1
    # DELETE /airport_fares/1.json
    def destroy
      @airport_fare.destroy
      respond_to do |format|
        format.html { redirect_to operator_airport_fares_path(operator_id: @operator.id), notice: 'Airport fare was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_operator
        @operator = Operator.find(params[:operator_id])
      end
  
      def set_airport_fare
        @airport_fare = AirportFare.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def airport_fare_params
        params.require(:airport_fare).permit(:cabcat, :triptype, :triptime, :basedist, :basehr, :basechrg, :ratepkm, :waitingbtime, :waitingchrg, :notes, :operator_id)
      end
  end
  </code></pre>
  
  <p>My db schema says:</p>
  
  <pre><code>create_table "airport_fares", force: true do |t|
      t.string   "cabcat"
      t.string   "triptype"
      t.string   "triptime"
      t.decimal  "basedist",     precision: 8, scale: 2
      t.integer  "basehr"
      t.decimal  "basechrg",     precision: 8, scale: 2
      t.decimal  "ratepkm",      precision: 8, scale: 2
      t.integer  "waitingbtime"
      t.decimal  "waitingchrg",  precision: 8, scale: 2
      t.text     "notes"
      t.datetime "created_at"
      t.datetime "updated_at"
      t.integer  "operator_id"
    end
  </code></pre>
  
  <p>The problem is when I try this in my console: <code>AirportFare.first.operator</code>. This leads to the error:</p>
  
  <pre><code>NoMethodError: undefined method 'operator' for #&lt;AirportFare&gt;. 
  </code></pre>
  
  <p>Where is the problem?</p>