Lint/AmbiguousBlockAssociationで怒られたお話
かずまです。
Railsで開発していて、Haml-lintで怒られたので、その対処法のメモを残しておきます。
今回怒られたケース
- formの中のSelect box
- i18nを使いたいからmapを使う
= f.select :season, Model.seasons.map { |k, _| [t("activerecord.enum.model.season.#{k}"), k] }
こんな感じで書くと、怒られる。
Lint/AmbiguousBlockAssociation: Parenthesize the param Model.seasons.map { |k, _| [t("activerecord.enum.model.season.#{k}"), k] } the block will be associated with the Model.seasons.map method call.
ググっても出てこないので、解決してみる。
解決方法
selectとmapのメソッドが曖昧になってるからselectの後ろに()入れろよみたいな感じみたいなので、
= f.select(:season, Model.seasons.map { |k, _| [t("activerecord.enum.model.season.#{k}"), k] })
こうやってすればOK!
これでhaml-lintに怒られないで済みます。
ちゃんとエラーを読んでもなかなかわからない、ググっても出てこないのは結構つらいです。