Skip to content

Possible to render a Phlex fragment from an ERB turbo_stream block? #315

@nimmolo

Description

@nimmolo

As I learned from this comment it works to pass a component as the second argument of turbo_stream.replace:

render turbo_stream: [
  turbo_stream.replace("a", Components::A.new),
  turbo_stream.replace("b", Components::B.new)
]

But is it possible to pass a fragment?

render turbo_stream: [
  turbo_stream.replace("a", Components::A.new(**args).call(fragments: ["A1"])),
  turbo_stream.replace("b", Components::B.new(**args).call(fragments: ["B1"]))
]

This is not working for me, I'm getting ActionView::Template::Error: wrong number of arguments (given 1, expected 0).

I guess I could make the fragment a sub-component.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions