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) %>

Reply
<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>
Reply

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

Reply
Join the discussion
Create an account Log in

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

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

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