0
0

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 3 years have passed since last update.

CarrierWaveで「Nil location provided. Can't build URI.」が出た時の対処法

Posted at

環境

ubuntu(wsl)
Rails 6.0.3
ruby 2.5.1
CarrierWave

想定状況と原因

エラーの箇所がこちら

view/user/show.html.slim
 = link_to image_tag(user.image.url), user

一旦Userモデルの中身を調べてみます。
↓Userモデルの中身

name: "藤田 翔太",
  email: "jeromy_weimann@wehner.info",
  password_digest: [FILTERED],
  admin: false,
  image: nil,

imageの値がnilになっているのが原因のようです。

解決策

解決策1. nilとなっているユーザーを削除する。

rails cなどでnilになっているユーザーを探して削除する。

解決策2. デフォルト画像の設定をする

image_uploader.rbに以下を追加します。

app/uploaders/image_uploader.rb
  def default_url(*args)
    'default.png'
  end

app/assets/imagesに画像を置いたら終わりです。

参考文献

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?