0
1

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

text_fieldを使うとwrong number of arguments (given 3, expected 1..2)で怒られる

Posted at

下記のようにf.text_fieldを使ったら怒られました。

<%= f.text_field :parent_category, "", id: "search_category" } %>
=> wrong number of arguments (given 3, expected 1..2)

え!こんな初歩的なことで。
Referrenceを見ても第3引数まで定義してるようなんですが。。
https://railsdoc.com/page/text_field

と思ったらこれ、text_fieldf.text_fieldでわけてるっぽいです。
text_fieldtext_field_tagのことなんですかね。

よくよく見るとf.objectと関連付けているときは、引数は2つまでと書いてありました。

なので、上記リファレンスに記載はなかったものの、下記のように実装したらうまくいきました。

<%= f.text_field :parent_category, { value: "", id: "search_category" } %>

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?