Ruby on rails 使用rails和回形针进行多重上传
我将按照本教程使用回形针的多次上传。 但是,当我添加文件时,我会收到flash通知,确认画廊已成功添加,但没有上载图像。我确信它是在我的控制器中实现的 gallery_controller.rbRuby on rails 使用rails和回形针进行多重上传,ruby-on-rails,ruby,paperclip,multi-upload,Ruby On Rails,Ruby,Paperclip,Multi Upload,我将按照本教程使用回形针的多次上传。 但是,当我添加文件时,我会收到flash通知,确认画廊已成功添加,但没有上载图像。我确信它是在我的控制器中实现的 gallery_controller.rb def update @gallery = Gallery.friendly.find params[:id] respond_to do |format| if @gallery.save if params[:exhibition_images_attrib
def update
@gallery = Gallery.friendly.find params[:id]
respond_to do |format|
if @gallery.save
if params[:exhibition_images_attributes]
params[:exhibition_images_attributes].each { |image|
@gallery.exhibition_images.create(image: image)
}
end
format.html { redirect_to @gallery, notice: 'Gallery was successfully updated.' }
format.json { render :show, status: :ok, location: @gallery }
else
format.html { render :edit }
format.json { render json: @gallery.errors, status: :unprocessable_entity }
end
end
end
def edit
@gallery = Gallery.friendly.find params[:id]
@image = @gallery.exhibition_images.new
end
private
def gallery_params
params.require(:gallery).permit(:title, exhibition_images_attributes: [:image])
end
上传表单
<%= bootstrap_form_for(@gallery, :html => {:multipart => true}, layout: :horizontal, label_col: "col-sm-2", control_col: "col-sm-10") do |f| %>
<%= f.text_field :title %>
<%= f.fields_for :exhibition_images do |f| %>
<%= f.file_field "image[]", type: :file, multiple: true %>
<% end %>
<%= f.submit "Create/Update", class: "btn btn-primary" %>
<% end %>
画廊.rb
class Gallery < ActiveRecord::Base
extend FriendlyId
friendly_id :title, use: :slugged
belongs_to :guide
has_many :exhibition_images, :autosave => true
accepts_nested_attributes_for :exhibition_images
end
展览图片.rb
class ExhibitionImage < ActiveRecord::Base
belongs_to :gallery, :autosave => true
has_attached_file :image, styles: { small: "100x100", guide: "500x500" }
validates_attachment_content_type :image, :content_type => ["image/jpg", "image/jpeg", "image/png", "image/gif"]
end
您是否可以将执行更新操作的参数包含在question@bjhaid添加了参数,thanksI是指日志中的参数