2011-11-02 67 views
16

我有一個垃圾回形針和多個圖像'我實現active_admin和產品更新很好,但是,我不能上傳或編輯多個圖像,我有是這樣的:Paperclip + Active_admin + Rails 3.0.10多個圖像

form :html => { :multipart => true } do |f| 
    f.inputs "Details" do 
    f.input :name 
    f.input :created_at, :label => "Publish Product at" 
    f.input :category 
    end 

    f.inputs "Images" do 
    f.has_many :assets do |p| 
     p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb)) 
     p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove' 
    end 
    end 

    f.inputs "Content" do 
    f.input :description 
    end 
    f.buttons 
end 

和...

f.inputs "Images" do 
    f.has_many :assets do |p| 
     p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb)) 
     p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove' 
    end 
    end 

我要上傳圖片,但是當我創建一個新的資產這有失蹤的圖像默認不安裝正確的形象,我想因爲圖像路徑上傳不正確。我的資產模型是:

class Asset < ActiveRecord::Base 
    belongs_to :product 
    has_attached_file :asset, :styles => { :large => "340x330", :medium => "140x80>", :thumb => "70x70>" }, 
    :url => "/products/:id/:style/:basename.:extension", 
    :path => ":rails_root/public/products/:id/:style/:basename.:extension" 
end 

如何修改我的資產表單以像我想要的那樣工作?謝謝!

+1

您應將解決方案移動到答案,並選擇自己的回答。這將從未回答的問題列表中刪除你的問題,並給你另一個徽章 –

+0

克里斯完成... – Stanmx

回答

7

解決方案

你好,這裏是解決方案,關鍵是如何在formtastic工作嵌套的屬性...

form :html => { :multipart => true } do |f| 
    f.inputs "Product information" do 
    f.input :name 
    f.input :description 
    end 

    f.inputs "Product images" do 
    f.has_many :assets do |p| 
     p.input :asset, :as => :file, :label => "Image",:hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb)) 
     p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image' 
    end 
    end 

    f.inputs "Product details" do 
    f.input :category, :label => "Category", :hint => "Select one category" 
    f.input :height 
    f.input :width 
    f.input :depth 
    f.input :color, :label => "Color", :hint => "Select one color" 
    f.input :sku, :label => "SKU" 
    f.input :price 
    end 
    f.buttons 
end 
+0

嗨,我試過這個,但得到「未定義的方法'has_many'爲零:NilClass」 – Richlewis

+0

我得到錯誤的參數數量... –

+0

請檢查這個http://stackoverflow.com/questions/33081836/multiple-image-upload-in-active-admin-ror我也嘗試但不工作 – Harman

相關問題