0

I have an API method that's implemented just like this:

  def change_status_operacao

    if @user.change_status_operacao(params[:status], params[:empilhadeira_id].to_i, params[:motivo_id].to_i)
      emp = ModeloEmpilhadeira.find(params[:empilhadeira_id].to_i)
      ActionCable.server.broadcast "filas", {fila: "aguardando", object_dom: render(partial: "application/operacao_detalhe", locals:{ empilhadeira: emp})}

      render json: { message: I18n.t("app.change_status_success") }, status: 200
    else
      render json: { errors: I18n.t("app.change_status_error") }, status: 400
    end

  end

The problem is, when I'm doing render(partial: "application/operacao_detalhe", locals:{ empilhadeira: emp}) for rendering a html content for my action cable channel, it seems to be responding my api call with that content, instead of the render right bellow, with 200 code. If I take out that broadcast, it works correctly, but I need to pass that html rendered to my channel. So how can I call that render method so it doesn't respond to the api call?

Ronan Lopes
  • 3,320
  • 4
  • 25
  • 51

1 Answers1

1

You can call render only once in a method. When you call render to generate the partial, that partial will be used as response.

Try render_to_string to send the partial through the channel.

thaleshcv
  • 752
  • 3
  • 7
  • Got it, but render_to_string is getting the same result for me. Isn't there another wai to get the html content as a string for a partial? – Ronan Lopes Aug 04 '17 at 18:42