I use GitHub - rails/request.js from stimulus controller to do a request that returning turbo_stream response
import { Controller } from "@hotwired/stimulus"
import onScan from "onscan.js"
import { patch } from "@rails/request.js";
// Connects to data-controller="checkout"
export default class extends Controller {
static values = {
sellingId: Number
}
connect() {
let sellingId = this.sellingIdValue
onScan.attachTo(document, {
suffixKeyCodes: [13], // enter-key expected at the end of a scan
onScan: function (sCode, _) { // Alternative to document.addEventListener('scan')
patch(`/sellings/${sellingId}/add-item`, {
body: { "selling": { "inventory_id": sCode } },
contentType: "application/json",
responseKind: "turbo-stream"
})
},
});
onScan.setOptions(document, {
minLength: 1 // change the quantity to 5 for every scan
});
}
}
my controller are like this
def add_item
idnya = params.require(:selling).permit(:inventory_id)[:inventory_id]
if idnya && @selling.update_entry(idnya)
respond_to do |format|
format.html { redirect_to selling_path(@selling), notice: "Item was successfully Added." }
format.turbo_stream { flash.now[:notice] = "Item ditambahkan." }
end
else
render :show, status: :unprocessable_entity, notice: "Item not found"
end
end
the problem is I got the correct response from console log, its 422 and the response is the show page rendered with the notice (the html page that I want)
problem is my view in the browser window is not changed at all