That's a great one!
I'd suggest using
<button type="button"> elements instead of links. This way you don't have to use
event.preventDefault() because by default a button doesn't do anything.
Also, for both links and buttons, the default Stimulus action is
click so the
click-> part in the
data-action is optional.
Well done! Keep the Stimulus JS tutorials coming!
I wonder if there is a tutorial you could assemble where we'd see Turbolinks and Stimulus working together, to provide some context around why Basecamp promotes them.
Even cooler would be a use case where someone today is typically reaching for Rails with React, but instead having the tutorial depicting how the Rails/Turbolinks/Stimulus combo would solve the same use case.
Great episode, I've been using Cocoon in past projects to add a "content section block" to a page, which then has different types of content associated to it (ie textarea, text with image, image gallery, etc.), so that it can then be reordered if needed.
I'd like to use more Stimulus moving forward, so interested in trying this technique out.
One part that I could never quite suss out, was when adding a content section block with a file auto uploader, such as jQuery File Upload (for multiple images/or documents) I couldn't upload anything until the content section block was saved to the database via a page save.
I guess with Stimulus, a new nested field could be saved to the database within the Stimulus controller, when it's added to the form? Then there would be an ID to use for any files to upload against.
Saying that, with a move away from jQuery, would Stimulus be able to deal with file uploads in a simular way to jQuery File Upload or is it best to leave that sort of thing to ActiveStorage?
Hey there! first comment here, trying to follow up the tutorial but missing the template.rb file you're using to start the project... i'm quite sure missing something basic :)
can someone help?
you can find it here: https://github.com/excid3/jumpstart. See readme for instructions.
But frankly, I don't like using this template. In more than a few tutorials that this template is used, I encounted bugs that only slowed down the progress of following through the tutorial, instead of helping it.
Because the jumpstart script is constantly updated, older tutorials using it see a breakage.
Join 20,000+ developers who get early access to new screencasts, articles, guides, updates, and more.