14 Mar 2010, 21:12

Lisa Gay (1 post)

Let me first say, I’m really enjoying the book so far. I have been trying to go through the examples with writing the code myself to make sure I’m getting the concepts. I understand everything you are talking about in section 6.4; but trying to run the code in this section was a big leap in some missing code examples somewhere.

I ran this command and got an error that says find_by_number is an undefined method.

f = Flight.find_by_number ‘123’

Ok, so I could code this myself at this point I suppose. But my bigger question is how did the reservation table ever get created in the database. I ran the command ‘ruby script\generate resource reservation’ to get the files created. Then ran a ‘rake db:migrate’. But it seems that create the reservation table with an id column instead of with flight_id and passenger_id columns. How does the table reservation get created in the database so the code in section 6.4 will work correctly?


20 May 2010, 13:41

Jeff Cohen (19 posts)

Hi Lisa,

It sounds like you might be missing the migration for the Flight model (from p. 97):

ruby script\generate scaffold flight flight_number:integer departs_at:datetime arrives_at:datetime origin:string destination:string


After rake db:migrate, that should solve the find_by_number error you were getting.

Regarding the reservation, if you take a look at your migration file for the reservation table, you should see something like this:

def self.up
  create_table :reservations do |t| 
    t.integer :flight_id
    t.integer :passenger_id


That will provide the foreign keys that will associate a reservation to both a flight and a passenger.

Does this help at all?

  You must be logged in to comment