在我的项目中,用户有一家酒店,每家酒店都有与之关联的房间类型。简而言之,模型是
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
如果我执行命令:
@user = User.find(1)
@user.hotels.find(1).roomtypes.build(name: "something", maxguests: "2")
控制台返回:
#<Roomtype id: nil, name: "something", maxguests: 2, created_at: nil, updated_at: nil, hotel_id: 1>
出于某种原因,Roomtype id 和时间戳为零。任何想法为什么?