Answer the question
In order to leave comments, you need to log in
How to save file_field_tag later in carrierwave?
Here is my form, the idea was to upload several files at once in one form, loop through and create several pictures for the gallery.
I store pictures in carrierwave, but how can I transfer the result to
it from a regular file field. The parameter returns only the file names. In theory, according to it, I should load it from the temporary storage tmp. But I don't know how to do it.
How to transfer the file value from the file_field_tag field to @object.avatar. Or how can I organize another download of several files at once?
<%= bootstrap_form_for @gallery, :enctype =>"multipart/form-data" do |f| %>
<div class="row">
<div class="col-md-offset-4 col-md-4 col-xs-12">
<%= f.hidden_field :tour_id %>
<%= f.hidden_field :category_id %>
<%= f.hidden_field :type %>
<%= file_field_tag 'image_gallery1', :multiple => true%>
<%= file_field_tag 'image_gallery2', :multiple => true%>
<%= file_field_tag 'image_gallery2', :multiple => true%>
<%= f.primary "Сохранить", class: "btn btn-primary" %>
</div>
</div>
<% end %>
Answer the question
In order to leave comments, you need to log in
There must be an ActiveRecord model for gallery files. For example:
# Галерея
class Galery < ActiveRecord::Base
has_many :photos
accepts_nested_attributes_for :photos
end
#фотография
class Photo < ActiveRecord::Base
belongs_to :galery
# монтирование загрузчика :file -имя поля модели, где будет храниться имя файла
mount_uploader :file, FileUploader
end
# загрузчик
class FileUploader < CarrierWave::Uploader::Base
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
<%= form_for @galery do |galery_form| %>
<!-- такие то поля для галереи --->
<%= galery_form.fields_for :photos, @photos do |photo_fields| %>
Изображение: <%= photo_fields.file_field :file %>
<% end %>
<% end %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question