dimanche 19 avril 2015

Saving images from a URL on the front-end with Paperclip

I'd like to first state that I'm fully aware of saving images from a URL on the backend with the help of this post. What I'd like to do in this particular case is simply copy/paste the url into my avatar input field in my new and edit views.


Everything works fine when I first save the model instance but if I were to go back to the edit view, the path to where the image was saved becomes the value of the previously mentioned input field:



/system/users/avatars/000/000/001/original/d12d224a55502a7263efca696ffccefe2c900613?1429479645


Now if I were to save with this value filled in I'll receive this error upon update:



Paperclip::AdapterRegistry::NoHandlerError in ArtistsController#update
No handler found for "/system/users/avatars/000/000/001/original/d12d224a55502a7263efca696ffccefe2c900613?1429479645"


I was wondering if there was clean way to instruct the backend to only use a newly inserted URL image path (if there is one) and not to refer to the relative path where its currently saved.



<%= simple_form_for(@user) do |f| %>
...
<div class="form-inputs">
<%= f.input :avatar, as: :string %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>

Aucun commentaire:

Enregistrer un commentaire