Ask A Question


You’re not receiving notifications from this thread.

How do I display my uploaded picture?

Samantha O asked in General

In my view, I have this to upload an avatar. When I want to edit, the picture is gone and how do I view my uploaded picture in my show view? I don't make use of any gems.

<div  class="inputfield">
    <%= f.label :avatar  %>
    <%= f.label :avatar  do  %>
    <%= image_tag("avatarbackground", class:  "avatar-bg",        
    alt:  "avatar image", id:  "avatar-background", type:  
    "file") %>
    <%  end  %>
     <%= f.file_field :avatar, class:  "hidden"  %>
     <%= f.hidden_field :avatar_cache  %>

In my show view I use this:
<%= image_tag image_url(@store.avatar) %>

<div class="inputfield">
  <%= f.label :avatar %>
  <% if @store.avatar %>
    <%= image_tag(@store.avatar, class: "avatar-bg", alt: "avatar image", id:  "avatar-background", type: "file") %>
  <% end %>
  <%= f.file_field :avatar, label:  "Avatar" %>

Hi John, then I get "The asset "avatar.jpeg" is not present in the asset pipeline."
I am missing something I think.

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 79,047+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

    © 2023 GoRails, LLC. All rights reserved.