I have this form:
What I hoped to achieve here, is by clicking on this button, to fire a controller action
that will using turbo stream, replace this form with extra fields.
I made the request using fetch:
cep_search(event) {
event.preventDefault()
const token = document.getElementsByName(
"csrf-token"
)[0].content;
let formData = new FormData()
formData.append("tipo_unidade", "fisica");
formData.append("cep", this.cepTarget.value);
formData.append("authenticity_token", token);
fetch(this.urlValue, {
body: new URLSearchParams({
'tipo_unidade': 'fisica',
'cep': this.cepTarget.value,
'authenticity_token': token
}),
method: 'POST',
credentials: "include",
headers: {
"X-CSRF-Token": token,
"Accept": 'text/vnd.turbo-stream.html, text/html, application/xhtml+xml'
},
})
}
And it fires the controller:
Processing by UnidadesController#render_form as TURBO_STREAM
Parameters: {“tipo_unidade”=>“fisica”, “cep”=>“01548030”, “authenticity_token”=>"[FILTERED]", “empresa_id”=>“takitani”}
User Load (0.7ms) SELECT “users”.* FROM “users” WHERE “users”.“id” = $1 ORDER BY “users”.“id” ASC LIMIT $2 [[“id”, 2], [“LIMIT”, 1]]
Empresa Load (0.7ms) SELECT “empresas”.* FROM “empresas” WHERE “empresas”.“slug” = $1 LIMIT $2 [[“slug”, “takitani”], [“LIMIT”, 1]]
↳ app/controllers/unidades_controller.rb:21:in `load_empresa’
Rendered unidades/_fisica.html.erb (Duration: 7.2ms | Allocations: 6099)
But it renders nothing, the response comes empty.
If I do it by using a form, it works fine.
What am I missing?
Thanks!