In my project, a user has a hotel, and each hotel has room types associated with it. Briefly, the models are
class User < ActiveRecord::Base
has_many :hotels
class Hotel < ActiveRecord::Base
belongs_to :user
has_many :roomtypes
class Roomtype < ActiveRecord::Base
attr_accessible :maxguests, :name
belongs_to :hotel
If I do the commands:
@user = User.find(1)
@user.hotels.find(1).roomtypes.build(name: "something", maxguests: "2")
The console returns:
#<Roomtype id: nil, name: "something", maxguests: 2, created_at: nil, updated_at: nil, hotel_id: 1>
For some reason, the Roomtype id and the timestamps are nil. Any ideas why?