Need better Rails specific instructions

I’m trying to use Stimulus with a Rails application, but the Stimulus website does not include any Rails-specific instructions. The Rails guides also don’t have any Stimulus-specific instructions.

The stimulus instructions manipulate raw HTML tags. Rails applications use ActionView form helpers by default. Are we meant to delete the form helpers? Combine the two? In short, how does

 <input data-hello-target="name" type="text">

translate in, for example,

  <div data-controller="hello">
    <%= form.label :content, style: "display: block" %>
    <%= form.text_field :content %>
  </div>

Actually I couldn’t find any information about making javascript controllers on the rails guides either.

How? Just the same way you add other HTML attributes to the form helpers.

<%= f.text_field :name, data: { controller: :example, action: 'blur->example#some-method' } %>

You might look also at some of the documentation on the various community sites. I agree, Hotwire.dev seems to go out of its way to ignore Rails. My secret suspicion is they are trying to appeal to a wider audience, some of whom (cough, JS devs) seem to be deeply suspicious or maybe jealous of Rails.

Walter

2 Likes

Also, unfortunately it is totally not clear that for documentation about Rails integration with Turbo and Stimulus one should look to the respective gems’ readmes:

Since they’re included by default in a new Rails App, most people starting out are not aware that the integration is completely in the gems. That’s also the reason why it’s missing from Rails documentation.