I have implemented an upload file system with carrierwave on ruby on rails. Currently each user have a single file, how can I do to when the user upload a new file, to add instead of overwrite? Allowing this way the user to have many files (only uploading one at each time)
this is my user controller:
def update #upload personal file
files = current_user.personal_files
files += params[:user][:personal_files]
current_user.personal_files = files
current_user.save
respond_to do |format|
if @user.save
# copy_file #make a copy of the uploaded file in public/files/data.xml for running in the bat file
format.html { redirect_to :back, notice: 'File was sucessfully uploaded!' }
format.json { render :show, status: :ok, location: @user }
else
format.html { render :edit }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
when I add a new file, it appears in the DB: [nil, "new_file"]. appears nil and overwrites the oldfile with the new.
and my view:
<%= form_for current_user, :method => :put, :html => {:multipart => true} do |f| %>
<h4 class="h1-form">Submit your personal performance file in order to WebProcessPAIR analyse your performance problems</h4>
<div class="field-wrap">
<div class="input-group image-preview">
<input type="text" class="form-control txt_color file_text log_placeholder" placeholder="Upload xml file" disabled="disabled">
<span class="input-group-btn">
<span class="btn btn-large btn-default btn-file">
<span class="glyphicon glyphicon-folder-open"></span>
Browse
<%= f.file_field :personal_files, accept: 'text/xml', multiple: true %>
</span>
<%= button_tag(:type => 'submit', :class => 'btn btn-info sbmt', :disabled => true) do %>
<i class="glyphicon glyphicon-share-alt"></i> Upload
<% end %>
</span>
</div>
</div>
<% end %>