我有一个名为Nonsense
which has_one of Foo
and的模型Bar
在我的控制器中,Nonsense
我需要为Foo
和创建相关条目Bar
我必须创建那些我需要在操作中显示链接的Foo
原因,因为应用程序的性质,在填写之前可能不知道详细信息。Bar
new
Nonsense
Foo
Bar
我在新行动中想要做的Nonsense
是
def new
@nonsense = Nonsense.new
@nonsense.bar = Bar.new
@nonsense.foo = Foo.new
...
现在我遇到的问题是,show
路径助手会抱怨 id@nonsense.foo
并且@nonsense.bar
是 nil。
在显示视图中,我只是这样@nonsense = Nonsense.find(params[:id])
做nonsense
accepts_nested_attributes_for :foo, :bar
知道为什么会发生这种情况吗?