Using Data in Stimulus
Learn to use data with Stimulus in this lesson.
We'll cover the following...
We'll cover the following...
With async, await, and fetch in our toolbox, we can get our Stimulus controller to contact the server directly to get the information about which concerts are sold out.
Sold-out concerts controller
On the Rails side, I’d like to set this up as its own route by adding a new singular resource to the routes.rb file:
This lets us put the API code in a new controller, which is good both from a conceptual standpoint—it’s a completely different kind of request—and from a practical standpoint—as its own route, it might be easier to separate into a designated server later on.
The controller is similar to what were were sending earlier in this chapter via Gon:
We’re returning a JSON file to be parsed on ...