[英]How do I tell my simple_form object to return an array with just the selected IDs and not any empty values?
[英]How do I return the object from a collection with simple_form?
我有一个simple_form输入字段,如下所示:
<%= f.input :parents, collection: (@node.family_tree.nodes - @node.parents - [@node]).uniq, label: "Parent 1" %>
但这会产生如下的HTML:
<option value="13">Jack</option>
其中value
是从集合中选择的对象的ID
。
但是,我希望将整个对象作为AR对象或数组返回。 例如,我很希望能够得到这样的东西:
<%= f.input :parents, collection: (@node.family_tree.nodes - @node.parents - [@node]).uniq, value_method: :parents, label: "Parent 1" %>
产生这个:
<option value="[#<Node id: 36, family_tree_id: 2, created_at: "2015-01-28 23:19:28", updated_at: "2015-01-28 23:19:28", name: "Mesty", ancestry: "13/35", ancestry_depth: 0, max_tree_depth: 0>]">Resty</option>
但是使用value_method: :self
不起作用。
因此,使用这些例子中,我怎么返回整个节点对象id=13
,而不是仅仅是13
?
似乎您应该使用simple_form的f.association
而不是f.input
来处理关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.