All threads / How do I display my uploaded picture?
Ask A Question

Notifications

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  %>
</div>

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" %>
</div>

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

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

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

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

    logo Created with Sketch.

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

    © 2022 GoRails, LLC. All rights reserved.