Ruby on rails Rails 3创建默认的嵌套对象

Ruby on rails Rails 3创建默认的嵌套对象,ruby-on-rails,ruby,activerecord,Ruby On Rails,Ruby,Activerecord,我有一个表单,用户注册并创建一个帐户、一个用户和一个网站 def new @account = Account.new @account.users.build @account.websites.build ... end def create @account = Account.new(params[:account]) ... 一切正常。现在,我想创建一个带有Page.title=“homepage”和Page.body=“”的默认页面 我该怎么做?我尝试了不

我有一个表单,用户注册并创建一个帐户、一个用户和一个网站

def new
  @account = Account.new
  @account.users.build
  @account.websites.build
  ...
end

def create
  @account = Account.new(params[:account])
  ...
一切正常。现在,我想创建一个带有Page.title=“homepage”和Page.body=“”的默认页面


我该怎么做?我尝试了不同的选择,但没有成功。例如,我这样做
@account.websites.pages.build
,我得到了[]:ActiveRecord::Relation的
未定义方法页面
@account.websites
返回的集合是一个数组,rails无法直观地知道您试图在其上创建关联对象的集合的哪个成员。。。您需要指定要为哪个网站构建页面,即

@account.websites.first.pages.build

@account.websites
返回的集合是一个数组,rails无法直观地知道您试图在该集合的哪个成员上创建关联对象。。。您需要指定要为哪个网站构建页面,即

@account.websites.first.pages.build

尝试
@account.websites.build.pages.build
尝试过,但是我得到了nil类
@account.websites[0].pages[0].title=“homepage”
尝试过,但是我得到了nil类
@account.websites[0].pages[0]的未定义方法标题。title=“homepage”