Created
May 10, 2012 22:29
-
-
Save tomciopp/2656302 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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