我有一个名为Nonsensewhich has_one of Fooand的模型Bar
在我的控制器中,Nonsense我需要为Foo和创建相关条目Bar
我必须创建那些我需要在操作中显示链接的Foo原因,因为应用程序的性质,在填写之前可能不知道详细信息。BarnewNonsenseFooBar
我在新行动中想要做的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
知道为什么会发生这种情况吗?