Skip to content

Instantly share code, notes, and snippets.

@tomciopp
Created May 10, 2012 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomciopp/2656302 to your computer and use it in GitHub Desktop.
Save tomciopp/2656302 to your computer and use it in GitHub Desktop.
Models with their associations
class Reservation < ActiveRecord::Base
belongs_to :load
has_one :bid
end
class Load < ActiveRecord::Base
has_many :bids, :dependent => :delete_all
has_one :reservation
end
class Bid < ActiveRecord::Base
belongs_to :load
belongs_to :reservation
end
The reservation migration only includes the references to the two tables
In my reservations controller I have the following code:
class ReservationsController < ApplicationController
before_filter :find_load
def new
@reservation = @load.reservation.build
end
private
def find_load
@load = Load.find(params[:load_id])
end
end
In my config routes file I have the following:
resources :loads do
resources :bids
resources :reservations
end
When I run my test suite I am getting undefined method build for nil:NilClass, why am I getting this issue?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment