Ruby on rails 保留嵌套字段中的字段\u以防出现错误

Ruby on rails 保留嵌套字段中的字段\u以防出现错误,ruby-on-rails,nested-attributes,Ruby On Rails,Nested Attributes,我有一张表格 = form_for(@user_group, :html => {:multipart => true}do |f| = f.fields_for :image, @user_group.build_image do |ff| = ff.file_field :file // other fields go here 它可以工作,但如果出现验证错误,它将重新命名,并且选定的文件将消失(其他字段不起作用,包括其他嵌套属性)。 但图像对象存在: def cr

我有一张表格

= form_for(@user_group, :html => {:multipart => true}do |f|
  = f.fields_for :image, @user_group.build_image do |ff|
    = ff.file_field :file
// other fields go here
它可以工作,但如果出现验证错误,它将重新命名,并且选定的文件将消失(其他字段不起作用,包括其他嵌套属性)。 但图像对象存在:

def create
    @user_group = User::Group.new(user_group_params)
    if @user_group.save
      redirect_to @user_group
    else
      ap @user_group.image
      render :new
    end
  end
打印此文件:

#<Image:0x007fbf11b902a8> {
               :id => nil,
      :imageble_id => nil,
    :imageble_type => "User::Group",
             :file => #<ImageUploader:0x007fbf11b46dd8 @model=#<Image id: nil, imageble_id: nil, imageble_type: "User::Group", file: nil, created_at: nil, updated_at: nil>, @mounted_as=:file, @cache_id="1441368278-5413-2848", @filename="snapshot3.png", @original_filename="snapshot3.png", @file=#<CarrierWave::SanitizedFile:0x007fbf11b44560 @file="/home/oleg/projects/10levels-rails/public/uploads/tmp/1441368278-5413-2848/snapshot3.png", @original_filename=nil, @content_type="image/png">, @versions={:thumb=>#<ImageUploader::Uploader70228906242320:0x007fbf11b44510 @model=#<Image id: nil, imageble_id: nil, imageble_type: "User::Group", file: nil, created_at: nil, updated_at: nil>, @mounted_as=:file, @parent_cache_id="1441368278-5413-2848", @cache_id="1441368278-5413-2848", @filename="snapshot3.png", @original_filename="snapshot3.png", @file=#<CarrierWave::SanitizedFile:0x007fbf11b39408 @file="/home/oleg/projects/10levels-rails/public/uploads/tmp/1441368278-5413-2848/thumb_snapshot3.png", @original_filename=nil, @content_type="image/png">, @versions={}>}>,
       :created_at => nil,
       :updated_at => nil
}
#{
:id=>nil,
:imageable_id=>nil,
:imageable_type=>“用户::组”,
:file=>,
:创建时间=>nil,
:更新时间=>nil
}

似乎只有文件有问题

您可以使用Carrierwave的缓存功能。它保留选定的文件


阅读

谢谢!但这对我不起作用。提交表单时,文件缓存参数为空
“文件缓存”=>“”