The whole idea of Hotwire is to prevent `Rails.ajax` calls. You can easily accomplish this with less code:
1. Replace the `output` target with a Turbo frame.
2. Add a value to the `data-controller` div with a `preview-url`: https://stimulus.hotwire.dev/reference/values
3. Change the `Rails.ajax` call with `let url = URL.new(this.previewUrlValue); url.searchParams.append('body', this.tweetTarget.value; this.outputTarget.src = url.toString();`
4. Change the `preview` action to render HTML with the same frame.
Now you have an automatic refreshing frame with less code.
strzibny|5 years ago
Turbo seemed more connected with existing models, and so I chose a Stimulus controller instead. But maybe I just don't know Turbo as much yet.
[0] https://stimulus.hotwire.dev/
edwinvlieg|5 years ago
1. Replace the `output` target with a Turbo frame. 2. Add a value to the `data-controller` div with a `preview-url`: https://stimulus.hotwire.dev/reference/values 3. Change the `Rails.ajax` call with `let url = URL.new(this.previewUrlValue); url.searchParams.append('body', this.tweetTarget.value; this.outputTarget.src = url.toString();` 4. Change the `preview` action to render HTML with the same frame.
Now you have an automatic refreshing frame with less code.
023984398|5 years ago
oh_boy|5 years ago