Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 最佳实践,如何使用select设置rails表单以管理引用\一个mongoid关联?_Ruby On Rails 3_Mongodb_Mongoid - Fatal编程技术网

Ruby on rails 3 最佳实践,如何使用select设置rails表单以管理引用\一个mongoid关联?

Ruby on rails 3 最佳实践,如何使用select设置rails表单以管理引用\一个mongoid关联?,ruby-on-rails-3,mongodb,mongoid,Ruby On Rails 3,Mongodb,Mongoid,我正在尝试在mongoid中为一个简单的关联设置一个带有select的表单 假设这个模型: class dog field: name references_one: owner end class owner field: name referenced_in :dog end 现在在我的表格上创建/编辑一只狗,我想创建一个选择列表,列出所有主人,并允许完成关联: = f.label "Owner" = f.select :owner, Ow

我正在尝试在mongoid中为一个简单的关联设置一个带有select的表单

假设这个模型:

class dog
  field: name 
  references_one: owner
end

class owner
  field: name
  referenced_in :dog
end
现在在我的表格上创建/编辑一只狗,我想创建一个选择列表,列出所有主人,并允许完成关联:

    = f.label "Owner"       
    = f.select :owner, Owner.list_all_owner
select的值应该是多少?我尝试了一切,id、JSON::ObjectId等等

谢谢

Alex

您是否尝试过:

= f.collection_select :owner_id, Owner.all, :id, :name

您是否尝试过:

= f.collection_select :owner_id, Owner.all, :id, :name

它不起作用,我这样做:=f.collection\u select:owner,owner.all,:id,:name,我不能放:owner\u id,因为它不是我的模型的一部分?这样做的目的是创建一个选择下拉列表,并使用内容id作为值。但显然,这不起作用,保存时也不会保留该值:(关于f.collection\u select:owner,owner.all,:name,:id(参数列表中的反向名称和id)。我相信下拉列表中要使用的标签在与该标签关联的值之前。它不起作用,我这样做:=f.collection\u select:owner,owner.all,:id,:name,我不能放:owner\u id,因为它不是我的模型的一部分。这样做的目的是创建一个select下拉列表,并使用内容id作为值。但显然这不起作用工作,保存时不保留该值:(关于f.collection\u select:owner,owner.all,:name,:id(参数列表中的反向名称和id)。我相信下拉列表中使用的标签位于与该标签关联的值之前。