Ruby on rails 使用CarrierWave上载多个图像

Ruby on rails 使用CarrierWave上载多个图像,ruby-on-rails,image,ruby-on-rails-4,carrierwave,ruby-on-rails-4.2,Ruby On Rails,Image,Ruby On Rails 4,Carrierwave,Ruby On Rails 4.2,我有以下设置 看法 现在,当我尝试选择多个图像并提交时,验证失败。 在控制台中,它显示了这一点 Started POST "/host/profile/photos/new" for 127.0.0.1 at 2015-09-11 16:07:44 +0530 Processing by Host::ProfileController#create_photo as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"6xo

我有以下设置

看法

现在,当我尝试选择多个图像并提交时,验证失败。 在控制台中,它显示了这一点

Started POST "/host/profile/photos/new" for 127.0.0.1 at 2015-09-11 16:07:44 +0530
Processing by Host::ProfileController#create_photo as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"6xo/+KoKHsdQxKYgMpSt337p/z1nIIPwy8aCOb//Qok=", "host_gallery"=>{"file_name"=>[#<ActionDispatch::Http::UploadedFile:0x007fe409c586c8 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-1edubzs>, @original_filename="AeeSyOb.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"AeeSyOb.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007fe409c586a0 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-14vmf57>, @original_filename="10996767_460989807398038_4893798671723861484_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"10996767_460989807398038_4893798671723861484_n.jpg\"\r\nContent-Type: image/jpeg\r\n">]}}
Geokit is using the domain: localhost
  User Load (0.3ms)  SELECT  `users`.* FROM `users`  WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
======================================================
["file_name", [#<ActionDispatch::Http::UploadedFile:0x007fe409c586c8 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-1edubzs>, @original_filename="AeeSyOb.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"AeeSyOb.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007fe409c586a0 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-14vmf57>, @original_filename="10996767_460989807398038_4893798671723861484_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"10996767_460989807398038_4893798671723861484_n.jpg\"\r\nContent-Type: image/jpeg\r\n">]]
==========================END============================
Unpermitted parameters: file_name

尝试此操作

您不允许上载零文件,允许的类型:jpg、jpeg、gif、pngSo选择此类型的文件我没有。。仅选择那些。让我们来。我发现此错误,请选择一张照片。看起来它无法确定正在选择两个图像。控制器操作中有什么需要更改的吗?
def create_photo

    params[:host_gallery].each{ |image|
      puts "======================================================"
      puts image.inspect
      puts "==========================END============================"
    }

    # render plain: params.inspect

    @host_gallery = HostGallery.new(host_gallery_params)
    @host_gallery.host_id = current_host.id

    if @host_gallery.save
      redirect_to host_profile_photos_url, notice: 'Photo was uploaded successfully created.'
    else
      flash[:error] = "Event could not be save. Please try again."
      render :new_photo
    end

  end


private

  # Only allow a trusted parameter "white list" through.
  def host_gallery_params
    params.require(:host_gallery).permit(:file_name)
  end
Started POST "/host/profile/photos/new" for 127.0.0.1 at 2015-09-11 16:07:44 +0530
Processing by Host::ProfileController#create_photo as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"6xo/+KoKHsdQxKYgMpSt337p/z1nIIPwy8aCOb//Qok=", "host_gallery"=>{"file_name"=>[#<ActionDispatch::Http::UploadedFile:0x007fe409c586c8 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-1edubzs>, @original_filename="AeeSyOb.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"AeeSyOb.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007fe409c586a0 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-14vmf57>, @original_filename="10996767_460989807398038_4893798671723861484_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"10996767_460989807398038_4893798671723861484_n.jpg\"\r\nContent-Type: image/jpeg\r\n">]}}
Geokit is using the domain: localhost
  User Load (0.3ms)  SELECT  `users`.* FROM `users`  WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
======================================================
["file_name", [#<ActionDispatch::Http::UploadedFile:0x007fe409c586c8 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-1edubzs>, @original_filename="AeeSyOb.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"AeeSyOb.jpg\"\r\nContent-Type: image/jpeg\r\n">, #<ActionDispatch::Http::UploadedFile:0x007fe409c586a0 @tempfile=#<Tempfile:/var/folders/y8/g0hc4kb54jq0mlhsqlh6clc40000gn/T/RackMultipart20150911-2195-14vmf57>, @original_filename="10996767_460989807398038_4893798671723861484_n.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"host_gallery[file_name][]\"; filename=\"10996767_460989807398038_4893798671723861484_n.jpg\"\r\nContent-Type: image/jpeg\r\n">]]
==========================END============================
Unpermitted parameters: file_name
def host_gallery_params
    params.require(:host_gallery).permit(file_name: [:filename])
  end