[RUBY] What to do when "Nil location provided. Can't build URI." Appears on CarrierWave

environment

ubuntu(wsl)
Rails 6.0.3
ruby 2.5.1
CarrierWave

Assumed situation and cause

Click here for the error

view/user/show.html.slim


 = link_to image_tag(user.image.url), user

Let's examine the contents of the User model once. ↓ Contents of User model

name: "Shota Fujita",
  email: "[email protected]",
  password_digest: [FILTERED],
  admin: false,
  image: nil,

It seems that the cause is that the value of ʻimage is nil`.

solution

Solution 1. Delete the user who is nil.

Find the user who is nil with rails c etc. and delete it.

Solution 2. Set the default image

Add the following to ʻimage_uploader.rb`.

app/uploaders/image_uploader.rb


  def default_url(*args)
    'default.png'
  end

Put the images in ʻapp / assets / images` and you're done.

References

-[Rails] basic image_tag and how to set default image

Recommended Posts

What to do when "Nil location provided. Can't build URI." Appears on CarrierWave
Nil location provided. Can't build URI. Resolution
What to do when Blocked Host: "host name" appears in Ruby on Rails
What to do when "call'Hoge.connection' to establish a connection" appears on rails c
What to do when javax.batch.operations.JobStartException occurs
What to do when CentOS cannot be started with VirtualBox on Catalina
What to do when a javax.el.PropertyNotWritableException occurs
Notes on what to do when EC2 is set up with t2.micro
What to do when undefined method ʻuser_signed_in?'
Notes on what to do when a WebView ClassNotFoundException occurs in JavaFX 12
What to do when you think you can't do Groovy-> Java in IntelliJ IDEA CE
What to do when debugging "Source not found"
What do you use when converting to String?
What to do when IllegalStateException occurs in PlayFramework
What to do when booting Ubuntu on WSL2 and getting "Process terminated with code 1"
What to do if you get a NoClassDefFoundError when trying to run eclipse on Java9
What to do when build fails by rbenv install / pyenv install with anyenv (Debian system)
What to do if you get a port error when docker-compose up on Mac
What to do if the Rails server can't start
What to do when The SSL certificate has expired
What to do when JSF tags do not become HTML
What to do if ClassNotFoundException occurs when starting Tomcat
What to do if rails server can't be stopped
What to do if TextToSpeech doesn't work on Android 11
What to do when a null byte error occurs
What to do when rails creates a 〇〇 2.rb file
What to see when IntelliJ doesn't start on Mac
Error ExecJS :: RuntimeUnavailable: What to do when it occurs
ParseException: What to do when Unparseable date is reached
What to do if you enable UFW on Ubuntu VM on GCP and you can't connect to SSH
What to do when a could not find driver appears when connecting to a DB in a Docker environment
What to do if a SAX Parser error occurs when using Liferay 7 / DXP on AWS
What to do when Rails on Docker does not reflect controller changes in the browser
What to do when it becomes Unable to find CDI BeanManager.
What to do when Method not found in f: ajax
What to do if audio is not available on discordrb
What to do when Cannot apply expression operators to method binding
What to do if you can't use the rails command
[Rails] What to do when the error No database selected and Unknown database appears in db: migrate
What to do if you go offline due to SSL certificate error when running Jenkins on Mac
[Ruby] What to do when the error "cannot load such file" appears when executing VS Code debug
What to do if you get a JNI shared library error when trying to build in Eclipse
What to do when javax.el.ELException: Not a Valid Method Expression: appears when the JSF screen is displayed