Therefore, I use simple_form to create my forms, but this is not a requirement.
What I'm trying to do is use simple_forms collection_check_boxes and pass an array to it.
I save my tags in configatron:
configatron.tags = [{:name => "wheels", :tagtype => "property"}, {:name => "roof", :tagtype => "property"}, {:name => "doors", :tagtype => "property"}]
Here is my tag model:
class Tag include Mongoid::Document embedded_in :taggable, polymorphic: true field :name field :tagtype end
Here is what I tried:
<%= f.collection_check_boxes :tags, @tags, @tags.map{|tag| tag.name}, @tags.map{|tag| tag.name} %>
where @tags
set to configatron.tags
in the controller
I just want work_check_boxes to work, and then before_save created the tag and inserted it into the current resource.
I read somewhere that you can map to a collected collection and select the contents of an element of this collection. If I get it right, override value_method? I donβt seem to remember how you can do this. I also want to pass the current tags of this resource :collection => resource.tags
so that these tags are marked when rendering.
Is there any way to do this? How can I manipulate form_builder to make this possible, if so, how? Should I use a different approach?
Sidenote: this functionality should also work with the main trunk, in some places the base chain will be used to add tags.
Tim brunsmo
source share