title: Code School Screencast - Rails App From Scratch - Part 1 Error: Couldn't find Trip with 'id'=
body: <p>Following codeschool.com's ruby screencast on making an app and ran into this error. </p>
  
  <p>Full error is</p>
  
  <blockquote>
    <p>ActiveRecord::RecordNotFound in DestinationsController#show</p>
    
    <p>Couldn't find Trip with 'id'=</p>
  </blockquote>
  
  <p><strong>The error applies to the @trip instance below</strong></p>
  
  <pre><code>GET /destinations/1.json   
  def show
  @trip = Trip.find(params[:trip_id])
  </code></pre>
  
  <p>Here is the applicable code from the destinations_controller.rb:</p>
  
  <pre><code> def show
      @trip = Trip.find(params[:trip_id])
      @destination = Destination.find(params[:id])
    end
  </code></pre>
  
  <p>Here is the Trip model </p>
  
  <pre><code>class Trip &lt; ActiveRecord::Base
      has_many :destinations
  end
  </code></pre>
  
  <p>And the Destination model</p>
  
  <pre><code>class Destination &lt; ActiveRecord::Base
  
          belongs_to :trip
      end
  </code></pre>
  
  <p>Routes</p>
  
  <pre><code>Rails.application.routes.draw do
    resources :destinations
  
    resources :trips do 
      resources :destinations
    end
  
    root to: 'trips#index'
  </code></pre>
  
  <p>Any help is greatly appreciated. :) :) :)</p>
  
  <p><strong>Update 1</strong>: From log files</p>
  
  <blockquote>
    <p>Started GET "/destinations/4" for ::1 at 2016-03-31 00:50:08 +0900
    Processing by DestinationsController#show as HTML   Parameters:
    {"id"=>"4"}</p>
    
    <p>[1m[35mDestination Load (0.6ms)[0m  SELECT  "destinations".* FROM
    "destinations" WHERE "destinations"."id" = ? LIMIT 1  [["id", 4]]</p>
    
    <p>[1m[36mTrip Load (0.3ms)[0m  [1mSELECT  "trips".* FROM "trips"
    WHERE "trips"."id" = ? LIMIT 1[0m  [["id", nil]]</p>
    
    <p>Completed 404 Not Found in 20ms (ActiveRecord: 1.8ms) </p>
    
    <p>ActiveRecord::RecordNotFound (Couldn't find Trip with 'id'=):<br>
    app/controllers/destinations_controller.rb:14:in `show'*</p>
  </blockquote>
  
  <p><strong>Update 2</strong> : the destinations_controller in its entirety. </p>
  
  <pre><code>class DestinationsController &lt; ApplicationController
    before_action :set_destination, only: [:show, :edit, :update, :destroy]
  
    # GET /destinations
    # GET /destinations.json
    def index
      @destinations = Destination.all
    end
  
    # GET /destinations/1
    # GET /destinations/1.json
    def show
      Rails.logger.debug params.inspect
      @trip = Trip.find(params[:trip_id])
      @destination = Destination.find(params[:id])
    end
  
    # GET /destinations/new
    def new
      @trip = Trip.find(params[:trip_id])
      @destination = Destination.new
    end
  
    # GET /destinations/1/edit
    def edit
      @trip = Trip.find(params[:trip_id])
      @destination = Destination.find(set_destination)
    end
  
    # POST /destinations
    # POST /destinations.json
    def create
      @trip = Trip.find(params[:trip_id])
      @destination = @trip.destinations.new(destination_params)
  
      respond_to do |format|
        if @destination.save
          format.html { redirect_to trip_destination_path(@trip, @destination), notice: 'Destination was successfully created.' }
          format.json { render :show, status: :created, location: @destination }
        else
          format.html { render :new }
          format.json { render json: @destination.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # PATCH/PUT /destinations/1
    # PATCH/PUT /destinations/1.json
    def update
      respond_to do |format|
        if @destination.update(destination_params)
          format.html { redirect_to @destination, notice: 'Destination was successfully updated.' }
          format.json { render :show, status: :ok, location: @destination }
        else
          format.html { render :edit }
          format.json { render json: @destination.errors, status: :unprocessable_entity }
        end
      end
    end
  
    # DELETE /destinations/1
    # DELETE /destinations/1.json
    def destroy
      @destination.destroy
      respond_to do |format|
        format.html { redirect_to destinations_url, notice: 'Destination was successfully destroyed.' }
        format.json { head :no_content }
      end
    end
  
    private
      # Use callbacks to share common setup or constraints between actions.
      def set_destination
        @destination = Destination.find(params[:id])
      end
  
      # Never trust parameters from the scary internet, only allow the white list through.
      def destination_params
        params.require(:destination).permit(:name, :description)
      end
  end
  </code></pre>