rails访问ActionDispatch错误



我试图在保存之前更改此请求的数据

{"image"=>{"picture"=>[#<ActionDispatch::Http::UploadedFile:0x10c865af8 @tempfile=#<File:/var/folders/bx/6z1z5yks56j40v15n43tjh1c0000gn/T/RackMultipart20130404-53101-1p7gv92-0>,
 @headers="Content-Disposition: form-data; name="image[picture][]"; filename="ATA.png"rnContent-Type: image/pngrn",
 @content_type="image/png",
 @original_filename="ATA.png">,
 #<ActionDispatch::Http::UploadedFile:0x10c865ad0 @tempfile=#<File:/var/folders/bx/6z1z5yks56j40v15n43tjh1c0000gn/T/RackMultipart20130404-53101-992qy5-0>,
 @headers="Content-Disposition: form-data; name="image[picture][]"; filename="ATA@2x.png"rnContent-Type: image/pngrn",
 @content_type="image/png",
 @original_filename="ATA@2x.png">],
 "album_id"=>"10"},
 "authenticity_token"=>"00/bnTiry5OIgGsXzeWIV2FccFiIRhsxuTg/Uep32H8=",
 "commit"=>"Submit",
 "utf8"=>"✓",
 "album_id"=>"10"}
控制器

def create
    @album = Album.find(params[:album_id])
        p = Image.find(params[:image][:picture])
        p.each do |pic|
            @image = @album.images.new(params[:image][p => :picture])
        end
        if @image.save
            flash[:notice] = "Successfully added image!"
            redirect_to [:admin, @album, :images]
        else
            flash[:notice] = "failed"
        end
    end

为什么这段代码会产生这个错误?如果这个错误得到解决,这段代码甚至可以为哈希中的每个:picture数组创建一个新的图像对象吗?

我猜这是一个简单的打字错误:

p.each do |pic|
  @image = @album.images.new(params[:image][p => :picture])
end

你做了一个do |pic|,但不要在任何地方使用pic

相关内容

  • 没有找到相关文章

最新更新