なんとなく納得いかなかったけど忘れない為にメモ。
form_for
<label>
<span class="btn btn-primary">
<input type="file" style="display:none" name="product[product_image]" include_hidden="false" >
編集してください
</span>
</label>
end
![スクリーンショット 2020-01-20 17.01.43.png](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F553847%2F8baea99b-62ea-9bf0-4a8f-25b320bf2120.png?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=f618f56fac53867dbddeabc5a2fe5eb6)
こうなる。
name部分はProductモデルのproduct_image_idカラム。使用gemはrefile。
f.attachment_fieldだとうまいこといかなかったのでinputタグを使用。labelタグで囲わないと画像を選択できない。なんでや。
追記
後日動作を確認したら選択はできてもupdateがされてなかった。腹立ったし時間もないのでf.attachment_fieldのデフォルトで動かすことにする。あーもー!