2016-04-13 52 views
0

ile başlamalıdır. "Flightwave ile birden çok dosya yüklemeyi deniyorum ve daha sonra bunları cloudinary'ye yüklemeyi deniyorum, ancak sorun görüntü URL'lerini psql array sütununa depolamaktır. bu hatayı alıyorum:Rails carrierwave birden çok karşıya yüklenir psql array değeri "{"

ActiveRecord::StatementInvalid (PG::InvalidTextRepresentation: ERROR: malformed array literal: "image/upload/v1460539908/u5fzgamsmt2rmnusees5.jpg" 
LINE 1: UPDATE "products" SET "images" = 'image/upload/v1460539908/u... 
            ^
DETAIL: Array value must start with "{" or dimension information. 
:UPDATE "products" SET "images" = 'image/upload/v1460539908/u5fzgamsmt2rmnusees5.jpg' WHERE "products"."id" = $1): 
app/controllers/products_controller.rb:26:in `create' 

Recieved parametreler birden fazla dosya gönderme, iyi görünüyor vb SQL:

INSERT INTO "products" ("title", "images", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["title", ""], ["images", "{u5fzgamsmt2rmnusees5.jpg,oznphywjmfykswlzzgit.jpg,x4kzdzgggzpnf7ho0w5e.jpeg,v4dlu4sdtbbtiaspvmu2.jpeg}"], ["created_at", "2016-04-13 09:31:48.306261"], ["updated_at", "2016-04-13 09:31:48.306261"]] 

O "} {" ile başlıyor, ya da Yazınsal olmadan bunu istiyor ""?

Göç:

class AddImagesToProducts < ActiveRecord::Migration 
    def change 
    add_column :products, :images, :string, array: true, default: [] 
    end 
end 

Şema:

create_table "products", force: :cascade do |t| 
t.string "title" 
t.text  "description" 
t.decimal "price" 
t.datetime "created_at",     null: false 
t.datetime "updated_at",     null: false 
t.integer "department_id" 
t.integer "category_id" 
t.string "images",  default: [],    array: true 
end 

Kontrol:

def create 
    @product = Product.new(product_params) 
    @product.save 
end 

private 

    def product_params 
    params.require(:product).permit(:title, {images: []}) 
    end 

class Product < ActiveRecord::Base 
mount_uploaders :images, ImageUploader 
end 

DÜZENLEME Değiştirilen params.require (: ürün) .permit (: Başlık, görüntü: [ ]) params.require (: ürün) .permit (: title, {images: []}) ama yine de hiçbir şey yok

EDIT2 Formu: Sorun, onlar psql'in json veya dizi sütun hiçbir desteğe sahip ben kullanıyordum cloudinary taş gibi

<%= stylesheet_link_tag "navbar" %> 
<%= form_for @product, :html => {:multipart => true} do |f| %> 
<p> 
<%= f.label :title %><br /> 
<%= f.text_field :title %> 
</p> 
<p> 
<%= f.file_field :images, multiple: true %> 
</p> 
<p><%= f.submit %></p> 
<% end %> 

cevap

0

Yani görünüyor. Bu yüzden çalıştığım şekilde ürün denetleyicisindeydim:

params[:product][:images].each do |image| 
    Cloudinary::Uploader.upload(image) 
end