jeudi 5 février 2015

How do I return the object from a collection with simple_form?


Vote count:

0




I have a simple_form input field that looks like this:



<%= f.input :parents, collection: (@node.family_tree.nodes - @node.parents - [@node]).uniq, label: "Parent 1" %>


But this produces HTML like this:



<option value="13">Jack</option>


Where the value is the ID of the object selected from the collection.


However, I would like for the entire object to be returned as an AR object or an array. For instance, I would love to be able to get something like this:



<%= f.input :parents, collection: (@node.family_tree.nodes - @node.parents - [@node]).uniq, value_method: :parents, label: "Parent 1" %>


Produces this:



<option value="[#<Node id: 36, family_tree_id: 2, created_at: &quot;2015-01-28 23:19:28&quot;, updated_at: &quot;2015-01-28 23:19:28&quot;, name: &quot;Mesty&quot;, ancestry: &quot;13/35&quot;, ancestry_depth: 0, max_tree_depth: 0>]">Resty</option>


But using value_method: :self doesn't work.


So, using these examples, how do I return the entire node object for id=13 rather than just the 13?



asked 59 secs ago







How do I return the object from a collection with simple_form?

Aucun commentaire:

Enregistrer un commentaire