0
0

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 5 years have passed since last update.

haml で書く時の注意(form_withで遷移しません編)

Posted at

haml で書く時に苦手意識を持っている初学者で
まずHTMLを書いて、webサービスで html -> haml にて書いている方がいると思います。
そういう方にありがちな落とし穴に一緒にハマったので、備忘録として残します。

haml で最初から書く人 

aaa.html.haml
 = form_with url: xxx_path
aaa.html
<form action="/xxx" method="get">

上記の用にヘルパーメソッドを用いる際に何がHTMLとして出力されるのか意識して書いてる

html -> haml の人

aaa.html
<form action="/xxx" method="get">

上記のようなhtml を haml に変換してからヘルパーメソッドを追記するので以下のようなhamlになる

aaa.html.haml
%form action = "/yyy" method="get"
  = form_with url: xxx_path

そして以下のような結果になる

aaa.html
<form action="/yyy" method="get">
  <form action="/yyy" method="get">
  </form>
</form>

そして記載変更時にform_withのURLだけ変更して(上記の場合、二段目のaction部分が変わる)、
「xxx_pathに飛ばないんです〜」と悩む

結論

何が出力されるのか考えてからヘルパーメソッドは使おう!
上記の用にピックアップされるとわかりやすいですが、長々と記載がされている一部分になってしまうと発見に時間がかかります。(ました)

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?