I want to hit my controller with a fetch()

I have a Stimulus controller that has two dates. I want to issue a GET to my controller with these two dates and have the controller return a partial filled with data relevant to these two dates. Seems simple enough.

Is there an example out there of how to do this simple thing with Turbo and Stimulus? It seems like this is an ideal use case for HTML over the wire… but the examples I have seen don’t seemingly do this.

Hi @dlazar!

I don’t know if that answers exactly your needs but GoRails has an interesting similar video: Dynamic Select Fields in Rails using Hotwire - YouTube

The select element, in that case, calls a method in the Stimulus Controller that in turns makes use of @rails/request.js to make a GET call to a non-Rest method on the Controller.
This method returns a turbo_stream.erb partial that will replace the dom with the right HTML.

Check out the repo
and specifically the select_controller.js as well as the addresses_controller.rb

Hope this helps! :slight_smile:

Thank you! I did finally find some articles by others about their journey and getting it working. I got it working myself, and in the process learned a few things. I will check out your info here too, and hopefully it just adds to my toolbox.

1 Like

Awesome! Glad to hear you solved it!