LoginSignup
3
3

More than 1 year has passed since last update.

Rails4 で form_for が multipart にならない

Last updated at Posted at 2015-08-17

「Rails4 の form_for は multipart: true を省略可能」という記事がある。
http://qiita.com/akishin/items/32e17717b1cff149572d

<%= form_for(@post) do |f| %>
<%= f.file_field :image %>
<% end %>

と書くとうまくいく。

だが、こんな風に。

<%= form_for(@post) do |f| %>
<%= file_field :post, :image %>
<% end %>

この場合だと f. を通して書かないと、ダメだ。
関連付けがされないようで、普通のフォームになってしまう。

この場合はちゃんと multipart を指定すること。

<%= form_for(@post, html: { multipart: true }) do |f| %>
<%= file_field :post, :image %>
<% end %>

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

3
3
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
3
3