0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

HamlでBootstrapの属性を書くときにUnbalanced brackets error発生

Last updated at Posted at 2021-09-26

###◆問題発生

.modal.fade{id: "exampleModal", tabindex: "-1", role: "dialog", aria-labelledby:  "exampleModalLabel", aria-hidden: "true"}

Bootstrapのモーダルを使おうと思ったら、属性を指定するところで

Haml::SyntaxError in Posts#show
Unbalanced brackets.

というエラーが出ました。
どうやらこの部分でエラーが出てしまっていたようです。

{... aria-labelledby: "exampleModalLabel", aria-hidden: "true"}

###◆Rubyではキーにハイフンが使えない

キーにハイフンが入っているとシンボルとして認識されないため、文字列に変換してあげる必要があります。
これはHamlの文法に限りません。

以下のように記述することで解決しました。

{... "aria-labelledby": "exampleModalLabel", "aria-hidden": "true"}

####◆参考

0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?