LoginSignup
0
0

More than 3 years have passed since last update.

Active Storageで画像アップロード機能を実装や! ❏Rails❏

Last updated at Posted at 2019-11-26

【その1】インストール

※Rails 5.2から搭載されています。

ターミナル
rails active_storage:install
rails db:migrate

【その2】モデルに設定を追記

1つのファイルならhas_one_attached :カラム名
複数ファイルならhas_many_attached :カラム名

モデル
has_one_attached :avatar
has_many_attached :images

実際にテーブルにカラムを追加する必要はありません。

【その3】表示する

ビューファイル
user.avatar

これを好きなところへ書いてください。
もちろんimage_tagなどを添えて。



超参考

https://railsguides.jp/active_storage_overview.html



ではまた!

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