I have a form that uploads pictures and keeps the old ones there:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {:multipart => true }) do |f| %>
<div class="form-group">
<label for = 'file-upload', class='btn btn-large btn-block btn-info'>
<span class="glyphicon glyphicon-upload" aria-hidden="true"></span> Upload Picture
<%= f.file_field :image, id: "file-upload", onchange: "this.form.submit()" %>
</label>
</div>
<% end %>
I am retrieving the uploaded images in my devise registration controller:
def edit
@images = Dir.glob("public/assets/images/users/#{current_user.id}/med/*")
end
I am generating an array of image paths for the current user in my view:
<% img_paths = Array.new %>
<% @images.each do |image| %>
<%img_paths.push("/assets/images/users/#{current_user.id}/original/#{image.split('/').last}")%>
<% end %>
I would like to select one fo these paths and update the user record with the new image details with something like this:
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: {method: :put }) do |f| %>
<%=f.select(:image, options_for_select(img_paths))%>
paperclip.update_current_image_with_my_new_image_from_img_path_url
<%end%>
Aucun commentaire:
Enregistrer un commentaire