Say I have a formtastic form that creates a Store and allows selection of Services it provides:
<%= semantic_form_for @store do |f| %>
<%= f.inputs :services, :as => :check_boxes, :collection => Service.all %>
<%= f.buttons %>
<% end -%>
I want to allow the user to add a new Service in case he doesn’t see it in the options, right from the form.
There are many examples for simple nested form element addition, say of a Task entry to a Project, and even a gem that helps with this, but I haven’t found any that create a new resource so it’ll show as part os checkbox or select options.
Got it working this way:
Added an id to the parent list item around the checkbox field listing, so it can be accessed by this js after submitting a text field with the new service name:
Then, in ServicesController: