Skip to content

Using turbostreams with wicked? #297

Open
@APysnack

Description

I'm confused about the pattern someone would use to replace an item in the dom using turbo streams in combination with wicked using the "show action". I'm trying to implement something like this, where In my scenario, I'm trying to replace a nested turboframe "foo" that exists on step_b using the "show" action:

def show
    respond_to do |format|
      case step
      when :step_a
        # dostuff
        
      when :step_b
        format.turbo_stream { render turbo_stream: turbo_stream.update("foo", partial: "partial_path", locals: { bar: params[:baz] }) }
        
      when :step_c
        # dostuff
      
      format.html { render_wizard }
    end
end

In step_b's view, I have several links, and they all link back to step b, but with different params. (I'm actually making an API call to render times in an appointment picker, and the params represent the dates for those times.

<%= link_to "Today", step_b_path(date: 03-14-23) %> will replace the "foo" turboframe with all the times for 3/14/23.
<%= link_to "Tomorrow", step_b_path(date: 03-15-23) %> will replace the "foo" turboframe with times for 3/15/23.

Ideally, the user can keep clicking these links, which will call the "show" function, which will use the turbostream to update the appointment times, until they finally pick and submit their appointment selection for that step in the form.

Once they select a time and click "submit" it calls the update action and proceeds to step_c

However, this doesn't appear to work. In practice, when I implement this, I click "submit" on step_a it

  1. Calls the "update" action (as expected)
  2. Calls the redirect_to_next next_step function (as expected)
  3. Calls the show function for :step_b (as expected)

But the view for step_b never renders. If I look at my network tab, I can see the partial content for the turbo_stream, but the page never renders step_b

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions