Ruby on Rails
Friday, November 1, 2019
ok, the plural got me beyond an error message, but i cant see the uploaded multiuploaded files. singles files work.
controller code:
@folder_attachment = FolderAttachment.new(folder_attachment_params)
@folder_attachment.company_id = current_user.cid
@folder_attachment.user_id = current_user.id
@folder = Folder.find_by_id(params[:folder_attachment][:folder_id])
respond_to do |format|
if @folder_attachment.save
format.html { redirect_to @folder , notice: 'Attachment was successfully created.' }
# format.json { render :show, status: :created, location: @folder_attachment }
else
format.html { render :new }
# format.json { render json: @folder_attachment.errors, status: :unprocessable_entity }
end
end
@folder_attachment.company_id = current_user.cid
@folder_attachment.user_id = current_user.id
@folder = Folder.find_by_id(params[:folder_attachment][:folder_id])
respond_to do |format|
if @folder_attachment.save
format.html { redirect_to @folder , notice: 'Attachment was successfully created.' }
# format.json { render :show, status: :created, location: @folder_attachment }
else
format.html { render :new }
# format.json { render json: @folder_attachment.errors, status: :unprocessable_entity }
end
end
def folder_attachment_params
params.require(:folder_attachment).permit(:company_id, :folder_id, :singlefile, :comment,:tags, {files: []})
end
params.require(:folder_attachment).permit(:company_id, :folder_id, :singlefile, :comment,:tags, {files: []})
end
==========
class FolderAttachmentUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
any ideas?
thx
On Fri, Nov 1, 2019 at 12:24 PM Ariel Juodziukynas <arieljuod@gmail.com> wrote:
Also, use "mount_uploader" singular for the single file and "mount_uploaders" plural for the multiple files--El vie., 1 nov. 2019 a las 12:44, tom (<tomabroad@gmail.com>) escribió:hi,--i want to have one uploader, but 2 forms:
<h3>Upload Single Attachment</h3>
<%= simple_form_for(FolderAttachment.new) do |form| %>
<%= form.error_notification %>
<div class="form-inputs">
<%= form.file_field :singlefile %>
</div>
<%= form.input :folder_id , :as => :hidden , :input_html => { :value => @folder_current.id} if @folder_current %>
<div class="form-inputs">
<%= form.input :comment %>
</div>
<div class="form-inputs">
<%= form.input :tags %>
</div>
<div class="form-actions">
<%= form.button :submit %>
</div>
<% end %>
<h3>Upload Multiple Attachments</h3>
<%= simple_form_for(FolderAttachment.new, :html => { :multipart => true } ) do |form| %>
<%= form.error_notification %>
<div class="form-inputs">
<%= form.file_field :files, multiple: true, name: "folder_attachments[files][]" %>
</div>
<%= form.input :folder_id , :as => :hidden , :input_html => { :value => @folder_current.id} if @folder_current %>
<div class="form-actions">
<%= form.button :submit %>
</div>
<% end %>--> no matter what i do, i always get errors on controller leve, eg: map or others. can an uploader only have 1 mount?class FolderAttachment < ApplicationRecord
belongs_to :folder
mount_uploaders :singlefile, FolderAttachmentUploader
mount_uploaders :files, FolderAttachmentUploader
endthx
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMenWxfarO9dCY%2B1N98tmMQuXtysykGj58tV%2B83pqNUEOA%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAPS3bcAAiPoY4kVqg8GscSjDcomSoOwzeXpe%3D%2B7xmu6gNfwSgQ%40mail.gmail.com.
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CADQqhMftZEaoDi%3DyQtUERERo9CyRzBQiK3gdzQ3VJcot07WGOA%40mail.gmail.com.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment