目的:
CarrierWave・Imagemagickというgemを使い、画像送信できる機能をつけたい!
しかし標題エラーが出たので解決したい。
結論:rails sでサーバー再立ち上げしたところ解決。
他解決案:
・ターミナル:brew install imagemagickでimagemagickを再インストール→bundle update
・ターミナル:spring stop、 spring startでspring再起動
参考URL: https://qiita.com/yokoyan/items/0f82fc3eede75cd6db55
★下記コード入力後、
class Message < ApplicationRecord
belongs_to :group
belongs_to :user
validates :content, presence: true, unless: :image?
mount_uploader :image, ImageUploader
end
localhost立ち上げたら、こちらのエラーが出ました。
NameError in MessagesController#index
uninitialized constant Message::ImageUploader
エラー要因:
コードの記述自体はあっていたが、imagemagickがうまくインストールされてなかった。
そこで、再度 brew install imagemagickでインストールし直したが、serverを再度立ち上げてなかったのでその内容が読み込まれてなかった。
学んだこと:
configやgemなどはインストールし直したりすると、その変更内容がサーバー上に反映されてなかったりするので、rails sでサーバー再度立ち上げるのが大事。