使用Rails上载载波多文件

时间:2015-03-18 16:58:35

标签: ruby-on-rails carrierwave

我正在使用Carrierwave file upload。单个文件上传工作正常。 有没有办法使用相同的代码进行多次上传?

我的模特:

class EmpDetail < ActiveRecord::Base
  mount_uploader :avatar, AttachmentUploader
  validates :emp_name, :avatar, presence: true
end

化身/ uploader.rb:

def store_dir
  "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end

def filename
  "#{model.emp_name}.#{file.extension}" if original_filename.present?
end

emp_detail / _form.html.erb:

<div class="field">
  <%= f.label :emp_name, :class => 'control-label' %>
  <div class="controls">
    <%= f.text_field :emp_name, :class => 'text_field' %>
  </div>
</div>

<div class="control-group">
  <%= f.label :avatar , :class => 'control-label' %>
  <div class="controls">
    <%= f.file_field :avatar, :class => 'file_field' %>
  </div>
</div>
<div class="form-actions">
  <%= f.submit "Create Emp Details", :class => 'btn btn-primary' %>
  <%= f.submit "cancel", method: :delete, data: { confirm: 'Are you sure you want to cancel' } %>
</div>

0 个答案:

没有答案