Turbo Stream in namespaced controller

I’m just trying out some of the awesome new stuff in my application and got a question regarding the Turbo Stream.

I read through the docs and tried to make the append/prepend method work when creating a new record.

That’s how my controller action looks like:

 def create
    @department = Current.institution.departments.build(department_params)
    if @department.save
      respond_to do |format|
        format.turbo_stream do 
          render turbo_stream: turbo_stream.prepend(:departments, partial: "admin/departments/department", locals: { department: @department } )
        end
      end
    else
      respond_to do |format| 
        format.js { }
      end
    end 
  end

I named my views according to the naming conventions and my table which lists all the record should be fine:

 <table class="highlight centered">
            <thead>
                <tr>
                  <th>Name der Fachabteilung</th>
                  <th>Kürzel</th>
                  <th>Aktion</th>
                </tr>
            </thead>
        <tbody>
          <%= render @departments %>
        </tbody>
      </table>

Now if I submit the form, I don’t get an error but the partial is not appended or prepended to the table, which should be the case I guess. If I specify an ID on the tbody like then it works, but shouldn’t it be working without specifying an ID aswell? If you look at the example in the docs, just every individual message has a dom_id field.

Could it be through the fact that my controller is namespaced?

Thanks! :slight_smile:

Yep, the id of the element you want to prepend to needs to match the target attribute of the <turbo-stream> element. Namespaced controllers aren’t the problem here.