Leonardo Siqueira

Joined

3,620 Experience
29 Lessons Completed
1 Question Solved

Activity

I had a similar issue, it happened for me when the element I target to replace is outside the partial I was replacing
eg:

# _some_partial.html.erb
<a href="..."></a>
# other_html.html.erb
<div id="turbo-target">
   <%= render 'some_partial' %>
</div>

If you use turbo_stream to replace turbo-target with your partial it will be the div turbo-target to dissapear from dom and when trying second time it does not works.

It work with the current flow, in your controller you can have

def create
  if @model.save
    redirect_to list_path, 'Model created successfully'
  else
    render :new, status: :unprocessable_entity
  end
end

and on application.html.erb have the same approach for toats using flash variables.
it will trigger the connect on stimulus controller and display the toast.

The approach showed on the video is more when you have complex pages and not only a regular CRUD.
having the ability to create reactive apps using this approach looks awesome.

Posted in store_accessor with jsonb nesting

Hello,

I will test your script to get a better understand about your first question (is this the correct way),

but, for the second question (How can I make the form helpers work with the keys of the virtual attributes as fields.)

You can use OpenStruct for this,

ex:

<%= form_for @foo do |f| %>
    <%= f.fields_for :permits, OpenStruct.new(@foo.permits) do |permit_fields| %>
          <%= permit_fields.text_field :key2 %>
    <% end %>
<% end %>