5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Rails] NameError in MessagesController#index uninitialized constant Message::ImageUploader エラー

Last updated at Posted at 2019-10-24

目的:
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でサーバー再度立ち上げるのが大事。

5
2
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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?