shopify-hotwire-sample icon indicating copy to clipboard operation
shopify-hotwire-sample copied to clipboard

Missing flash_messages partial

Open resistorsoftware opened this issue 2 years ago • 0 comments

I have officially moved out of my comfort zone with this fabulous pattern. I love it! Now I am using a Turbo based pattern. One problem I have yet to solve.

If I make views for a Turbo response, and tell the controller nothing much at all, other than

respond_to do |format|
    format.turbo_stream
    format.html
end

This will error out. Specifically what happens, is it has lost the context of the views, and the layout for the flash messages! Why I have zero clue. An interesting point is, if I inline the exact same view code, it works perfectly. No errors. So for now, I just use the inline code. Specifically, this is in a controller create method. I have a create.turbo_stream.erb response. It renders the same partial as the inline response below does.

<%= turbo_stream.replace "my-stuff" do %>
  <%= render partial: "cold/beers", locals: {stuff: @stuff} %>
<% end %>

So that block of code above, triggers a problem with views and layouts? But the inline response below works great. What am I missing here?

respond_to do |format|
  format.turbo_stream { render turbo_stream: turbo_stream.replace("my-stuff", partial: "cold/beers", locals: {stuff: @stuff}) }
end

I am curious though, as to why the conventional Rails approach, would be raising an exception. Reading the logs shows the nasty, where Rails says, Hey!! I cannot find /app/views/layouts/flash_messages.html when clearly that file is there.

Just my 0.02... love this pattern... I am exploiting it madly, but this little bug-a-boo kinda bites. I have no Rails experience to be able to quickly just go AHA! That is a whatchamacallit.

resistorsoftware avatar Mar 15 '22 14:03 resistorsoftware