2011-11-02 13 views
16

Mam crud z spinaczem i wieloma obrazami "Wdrażam active_admin i aktualizację produktu dobrze, ale, nie mogę nie przesyłać ani edytować wielu obrazów, formularz mam jest to:Spinacz + Active_admin + Rails 3.0.10 wiele obrazów

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 

i ...

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 

Chcę przesłać zdjęcia, ale gdy tworzę nowy zasób ten posiada brakujący obraz domyślny i nie przywiązują prawidłowego obrazu, myślę ponieważ ścieżka z obrazów nie jest poprawna do przesłania. Mój model aktywów to:

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 

w jaki sposób mogę zmodyfikować mój formularz aktywów, aby działał tak, jak chcę? Dziękuję Ci!

+1

należy przenieść swoje rozwiązania do odpowiedzi i wybrać własne odpowiedź. to usunie twoje pytanie z listy pytań bez odpowiedzi, a także dostaniesz kolejną odznakę –

+0

Chris jest gotowy ... – Stanmx

Odpowiedz

7

Rozwiązanie

Cześć, tu jest rozwiązanie, kluczem są, jak działają zagnieżdżonych atrybuty 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

cześć, próbowałem tego, ale otrzymałem "niezdefiniowaną metodę' has_many 'for nil: NilClass " – Richlewis

+0

Otrzymuję błędną liczbę argumentów ... –

+0

proszę sprawdzić ten http://stackoverflow.com/questions/33081836/multiple-image-upload-in-active-admin-ror Jestem również spróbować, ale nie działa – Harman

Powiązane problemy