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

【Rails】セレクトボックスの設置の仕方

Posted at

My Profile

プログラミング学習歴②ヶ月目のアカウントです!
プログラミングスクールで学んだ内容や自分が躓いた箇所等のアウトプットの為に発信しています。
また、プログラミング初学者の方にわかりやすく、簡潔にまとめて情報共有できればと考えています。
もし、投稿した記事の中に誤り等ございましたら、コメント欄でご教授いただけると幸いです。 

対象者

 
・セレクトボックスを表示させたい方

手順目次

1.select_tagを入力する

2.options_for_selectも入力する

実際の手順と実例

1.select_tagを入力する

そもそもselect_tagとは選択をする項目表示のメソッドです。

select_tag "name" , options_for_select({}) 

このように書きます。
name部分がparams ->値を拾うための文字列が入ります。

次でoptions_for_selectについて説明します

2.options_for_selectも入力する

上記のメソッドもいれると、、、、、

<%= select_tag "model", options_for_select({ "---Please choose---" => "" , "User" => "user" , "Book" => "book"})%>

選択項目の数をどんどん増やせるのでおすすめです!!

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?