0

Context: a form has a collection_select, but without a value that interests the user.

A second form allows to create a new entry that would populate the collection_select with a desired value.

Class Article has_many :tags

The create turbostream does render the object, but the form does not display the change & I suspect it is due to the atomicity of the form. the IDed div tag was tried both outside and inside the form_fields tag to the same neutered effect.

    <%= form.fields_for :tags do |tag| %>
      <div id='tags'>
          <%= f.collection_select(:tag, @tags, :id, :name) %>
      </div>
    <% end %> 

The turbo_stream file tris to replace the target. If f.collection_select is used, this generates an error as rails, handling the snippet does not know of the form's existence. Using select_tag, a tag is rendered and delivered but the div is not refreshed

<%= turbo_stream.replace "tags" do %>
  <div class='fade-in-div'>
    <%= select_tag :tag, options_from_collection_for_select(@tags, :id, :name) %>
  </div>
<% end %>

How can these options for select be updated with hotwire?

Jerome
  • 5,583
  • 3
  • 33
  • 76

1 Answers1

0

Functional answer that does not answer the question:

• the new data needs its own field
• make that an allowed attribute with the relevant accessor atrr_accessor
• process the new value
• update the record
• choose preferred path: redirect or turbo_stream a partial as a replacement of entire form.

Jerome
  • 5,583
  • 3
  • 33
  • 76