LoginSignup
6
1

More than 5 years have passed since last update.

railsのform_tagでデフォルト値を入れる方法

Posted at

form_forは勝手に入れてくれるけど、form_tagは自分で渡す必要があるぽい。

やり方は簡単

・第二引数に渡したい値を入れる。(text_field, text_areaとか)
・select_tagので、options_for_select使っている場合は、options_for_selectの中に第二引数として値を渡す。

参考例

Carモデルをいじりたいとき。

<%= form_tag path, method: 'patch' do %>
<%= text_area_tag :description, @car.description %>
<%= select_tag :type, options_for_select([['Sedan', 1], ['Eco', 2 ]], @car.type %>
6
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
6
1