Hamlファイルにclass名の指定をしたいのですが、どうしてもエラー文が表示されてしまいます。コードは下記に記載しています。今回の場合、いろんな場合を試してみました。クラス名の記述方法に関しては、下記の記事を参考にさせていただきました。
リンク内容
fieldクラスの、form.labelと、form.date_selectにクラス名を追加したい状態です。この二つのタグはそれぞれ違う記述法で試していますが、どちらのやり方もうまく行きません。この記述に対するエラー文がhamlファイルのしたにコードを挿入しておきます。また、エラー文の画像も挿入しておきました。確認お願いします。
リンク内容
_form.html.haml
= form_with(model: article, local: true) do |form| - if article.errors.any? #error_explanation %h2 = pluralize(article.errors.count, "error") prohibited this article from being saved: %ul - article.errors.full_messages.each do |message| %li= message .field = form.label{ :post_date, :class => 'f' } = form.date_select :post_date{ :class 'a' } .field = form.label :title = form.text_field :title .field = form.label :content = form.text_area :content .actions = form.submit
ActionView::SyntaxErrorInTemplate in ArticlesController#new Encountered a syntax error while rendering template: check = form_with(model: article, local: true) do |form| - if article.errors.any? #error_explanation %h2 = pluralize(article.errors.count, "error") prohibited this article from being saved: %ul - article.errors.full_messages.each do |message| %li= message .field = form.label{ :post_date, :class => 'f' } = form.date_select :post_date{ :class 'a' } .field = form.label :title = form.text_field :title .field = form.label :content = form.text_area :content .actions = form.submit Extracted source (around line #11): 9 10 11 12 13 14 %li= message .field = form.label{ :post_date, :class => 'f' } = form.date_select :post_date{ :class 'a' } .field = form.label :title
また、エラーに対するターミナルの記述も載せておきます。
ActionView::SyntaxErrorInTemplate (Encountered a syntax error while rendering template: check = form_with(model: article, local: true) do |form| - if article.errors.any? #error_explanation %h2 = pluralize(article.errors.count, "error") prohibited this article from being saved: %ul - article.errors.full_messages.each do |message| %li= message .field = form.label{ :post_date, :class => 'f' } = form.date_select :post_date{ :class 'a' } .field = form.label :title = form.text_field :title .field = form.label :content = form.text_area :content .actions = form.submit ): 1: = form_with(model: article, local: true) do |form| 2: - if article.errors.any? 3: #error_explanation 4: %h2 5: = pluralize(article.errors.count, "error") 6: prohibited this article from being saved: 7: %ul 8: - article.errors.full_messages.each do |message| 9: %li= message 10: .field 11: = form.label{ :post_date, :class => 'f' } 12: = form.date_select :post_date{ :class 'a' } 13: .field 14: = form.label :title 15: = form.text_field :title 16: .field 17: = form.label :content 18: = form.text_area :content 19: .actions 20: = form.submit app/views/articles/_form.html.haml:11: syntax error, unexpected ',', expecting '}' app/views/articles/_form.html.haml:11: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '{', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected ensure, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:11: syntax error, unexpected ',', expecting '}' app/views/articles/_form.html.haml:11: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '{', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected ensure, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:11: syntax error, unexpected ',', expecting '}' app/views/articles/_form.html.haml:11: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '{', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected ensure, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:11: syntax error, unexpected ',', expecting '}' app/views/articles/_form.html.haml:11: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '{', expecting ')' app/views/articles/_form.html.haml:12: syntax error, unexpected '}', expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected ensure, expecting ')' app/views/articles/_form.html.haml:21: syntax error, unexpected end, expecting ')' app/views/articles/new.html.haml:2
問題の確認と解決案があれば、どなたかご教授お願いします!
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/08/21 11:27 編集
2020/08/21 11:51 編集
2020/08/21 12:57
2020/08/21 21:51 編集
2020/08/22 07:07
2020/08/22 07:23
2020/08/22 10:33
2020/08/22 11:08
2020/08/27 08:19