前提・実現したいこと
hamlでタイトルにあるコードを書く方法が知りたい。
現在、個人アプリの開発にてカテゴリー機能を実装しています。
その中で、
<option value="<%= c.id %>"><%= c.name %></option> <option><%= c.name %></option>
このような文法の場合、hamlではどのように書くのでしょうか?
%option{value: "hoge"}
みたいに書くのはできるんですが、それよりも高度なコードになっているので、なかなか自分で実装できずに困っています。
ちなみに参考にしている記事は、以下の記事のセレクトボックスを表示するです。
https://qiita.com/kenzoukenzou104809/items/07f6b5f7fdcf2761ac8f
【追記】
##該当コード
_form.haml.html
= form_for(@post) do |f| .field .field-label = f.label :title, "snowB" .field-input = f.text_field :title .field .field-label = f.label :body, "ココがポイント!" .field-input = f.text_area :body .field .field-label = f.label :image, "snowB写真" .field-input = f.attachment_field :image .category = render partial: "category" .actions = f.submit "投稿する", class: "btn"
_category.haml.html
.categorySelect %select#pararent_category - @parent_categoryies.each do |c| = options_for_select([['= c.id', =c.name]])
##エラー文
_category.html.haml:4: syntax error, unexpected '=', expecting ']' ...ptions_for_select([['= c.id', =c.name]]) ... ^ _category.html.haml:4: syntax error, unexpected ']', expecting ')' ...for_select([['= c.id', =c.name]]) ... ^ _category.html.haml:5: syntax error, unexpected keyword_end, expecting ')' ...t.buffer << ("\n".freeze);; end;; _hamlout.buffer << ("</sel... ... ^~~ _category.html.haml:5: syntax error, unexpected keyword_ensure, expecting ')' ...:Util.html_safe(_erbout);ensure;@haml_buffer = @haml_buffer.... ... ^~~~~~ _category.html.haml:5: syntax error, unexpected keyword_end, expecting ')' ...uffer.upper if @haml_buffer;end; ... ^~~ _category.html.haml:8: syntax error, unexpected keyword_end, expecting ')' end ^~~

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/25 02:04
2020/08/25 02:48
2020/08/25 02:54
2020/08/25 03:22
2020/08/25 05:18
2020/08/25 07:06