form_forヘルパーでselectを利用する際に、options_from_collection_for_selectを利用した。その際、すでに保存されている値を呼び出す方法につまづいたので、メモを残しておく。
NG例。selectedで指定しようとしても取れない。
= f.select :id, options_from_collection_for_select(Users.all, :id, :username), {include_blank: true}, class: "form-control", selected: user.id
OK例。options_from_collection_for_selectの第三引数に指定してあげればOK
= f.select :user_id, options_from_collection_for_select(Users.all, :id, :username, user.id), {include_blank: true}, class: "form-control"