LoginSignup
1
1

Rails7+Hotwireによるstimulus.jsのフォルダの配下のコントローラの書き方

Posted at

はじめに

stimulus.jsのコントローラをフォルダで分けた際のHTML上での記述方法を解説します。

問題

JavaScript/controllers/test_controllerは
そのまま

<div data-controlelr="modal">
    <button data-action="click->modal#close">
        閉じる
    </button>
</div>

というふうに記述する。

しかし
JavaScript/controllers/users/test_controllerのactionを使用する際の書き方がわからなかった。

解決方法

JavaScript/controllers/users/test_controllerの記述方法は

<div data-controlelr="users--modal">
    <button data-action="click->users--modal#close">
        閉じる
    </button>
</div>

フォルダ配下のものは"--"で表現する

data-controlelr="users--modal"

おわりに

なかなか調べても出てこなかったので、同じように困った人のためにメモとして残します。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1