Home>
environment

macOS 10.15.5
Rails 5.2.4.2


The image is a picked-up image, but such a "mark that the image is not displayed" appears. However, I want to display the image set as the initial image normally.

The structure of the folder is like this.

public
∟ images
∟ default_icon.jpg


BD column name isimageis.

users_controller.rb

def create
    @user = User.new (
      name: params [: name],
      email: params [: email],
      image: "default_icon.jpg"
    )
    if @ user.save
      redirect_to ("/ users/# {@ user.id}")
    else else
      render ("users/new")
    end
  end


show.html.erb


  
    ">
  
<p><% = @ user.name%></p>
<p><% = @ user.email%></p>
<% = link_to ("edit", "/ users/# {@ user.id}/edit")%>

The mark that is not displayed appears.

What I tried

I changed the extension of the image to png and changed the image itself.
After that, I thought that it was necessary to set CSS, so I tried setting it, but there was no change.
I also tried restarting the server.
I also tried changing the browser.

  • Answer # 1

    I think it's easier to use a helper method called image_tag

    <% = image_tag @ user.image.url%>

    By the way, you need to use uploader such as CarrierWave to save the image.

Related articles