質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Haml

Haml(HTML abstraction markup language)は、HTML/XHTMLを効率的に記述するためのマークアップ言語および記法です。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

Q&A

1回答

830閲覧

「Rails」Haml記載時のフォームへルパーに対してのclass名の指定ができません。ご教示お願いします。

suirunakamura

総合スコア16

Haml

Haml(HTML abstraction markup language)は、HTML/XHTMLを効率的に記述するためのマークアップ言語および記法です。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

HTML

HTMLとは、ウェブ上の文書を記述・作成するためのマークアップ言語のことです。文章の中に記述することで、文書の論理構造などを設定することができます。ハイパーリンクを設定できるハイパーテキストであり、画像・リスト・表などのデータファイルをリンクする情報に結びつけて情報を整理します。現在あるネットワーク上のほとんどのウェブページはHTMLで作成されています。

CSS

CSSはXMLやHTMLで表現した色・レイアウト・フォントなどの要素を指示する仕様の1つです。

0グッド

0クリップ

投稿2020/08/21 10:11

編集2022/01/12 10:55

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

問題の確認と解決案があれば、どなたかご教授お願いします!

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

= form.date_select :post_date, class: 'a'

でどうでしょうか?
もしダメなら

= form.date_select :post_date, {}, class: 'a'

こちらも試してみてください

投稿2020/08/21 11:09

nasuk47

総合スコア311

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

suirunakamura

2020/08/21 11:27 編集

返信ありがとうございます!ご助言通りに変更修正してみました。しかし、エラーは変わらなかったようです。通常通りなら、記事通りの記述法でも、nasuk47さんのご提示していただいた方法でもエラーなく行けそうですが、、 そもそものクラス名の指定方法がおかしいのでは、なくて別に原因がある可能性はありそうですか?どうかよろしくお願いします。 https://gyazo.com/8f3476f2d604b14b51ddf435033bd1fa https://gyazo.com/9013c18c8d2459b27fb2804ffcdd5eec
nasuk47

2020/08/21 11:51 編集

labelも同じように書き換えましたか? label: 'a' ですね
nasuk47

2020/08/21 21:51 編集

suiruさん :label 'f' 僕 label: 'f' ` : ` の位置に注目してください
suirunakamura

2020/08/22 07:07

すみません。見落としていました、、 nasuk47さんの指摘通りに直した結果、labelにクラス名が付与されました。 https://gyazo.com/32efb21c1d9c3e3c74b22a275089afe1 https://gyazo.com/7cafb73fee135ec5838536ba3446722d しかし、labelの下のdate_selectにクラス名が付与されているのかどうかがわからない、、 その前に、date_selectが見つかりませんでした。どこにあるのでしょうか? すみません、恐縮ながら教えてください。
nasuk47

2020/08/22 07:23

date_selectはrubyの書き方でhtmlファイルに変換される時にselectタグに変換されたような、、、 なのでselectタグにクラスがついていたらついているのですがついていませんね。 回答の方にも書いてありませが `= form.date_select :post_date, {}, class: 'a' ` のように書くとどうでしょうか??
suirunakamura

2020/08/27 08:19

返信ありがとうございます! 調べてみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問