Ruby on rails 如何以简单形式设置集合中的当前值(使用mongoid)

Ruby on rails 如何以简单形式设置集合中的当前值(使用mongoid),ruby-on-rails,mongodb,mongoid,simple-form,Ruby On Rails,Mongodb,Mongoid,Simple Form,我的表格中有: = f.input :location_id, :collection => @locations, :include_blank => false, :selected => @video.location 这适用于我的“新”视图/操作,我看到了一个很好的位置列表供选择 但是,在“编辑”视图中,我看到的不是位置列表,而是一个输入字段,就像它是一个字符串一样,如下所示: Location: 4ebbc0f8e0ed180e91000002 你知道为什么我看不

我的表格中有:

= f.input :location_id, :collection => @locations, :include_blank => false, :selected => @video.location
这适用于我的“新”视图/操作,我看到了一个很好的位置列表供选择

但是,在“编辑”视图中,我看到的不是位置列表,而是一个输入字段,就像它是一个字符串一样,如下所示:

Location: 4ebbc0f8e0ed180e91000002
你知道为什么我看不到我的收藏吗

编辑:

弄明白了,我必须做:

= f.input :location_id, :collection => @locations, :include_blank => false, :selected => @video.location.id
= f.input :location_id, :collection => @locations, :include_blank => false, :selected => @video.location.id

此外,我忘记在我的编辑控制器woops:)中传递@locations。

从编辑的问题正文复制答案,以便从“未回答”过滤器中删除此问题:

弄明白了,我必须做:

= f.input :location_id, :collection => @locations, :include_blank => false, :selected => @video.location.id
= f.input :location_id, :collection => @locations, :include_blank => false, :selected => @video.location.id
另外,我忘了在我的编辑控制器中传递@locations,哎呀:)


~answer per

最好直接回答自己,而不是编辑问题。回答自己是个好主意…@user341458-如果你想重述解决方案作为自己的答案,我将删除我的答案。(请参阅详细说明为什么这会有帮助。)谢谢!