2016-08-09 14 views
0

has_many belongs_toリレーションを持つモデル製品とギャラリーがあります。ネストされたアトリビュート機能を実装しています。問題は次のとおりです。ギャラリーを追加すると、ギャラリーが2つ追加されます(下の図を参照)。enter image description hereActiveadminネストされた属性

CODE

form do |f| 
    f.inputs "Product" do 
     f.input :title, :required => true 
     f.input :description 
     f.input :price 
     f.input :display_image 
     f .input :product_detail, :hint => "Upload PDF file" 
     f.input :category 
    end 

    f.inputs 'Product Gallery' do 
     f.has_many :galleries, allow_destroy: true, new_record: 'Add Gallery' do |c| 
      c.input :image, :hint => c.template.image_tag(c.object.image.url(:thumb)) 
     end 
    end 
    f.inputs 'Product Specification' do 
     f.has_many :specifications, allow_destroy: true, new_record: true do |c| 
      c.input :specification_label 
      c.input :specification_details 
     end 
    end 
    f.actions 
end 

私はこの上の助けが必要。私はこれを解決することができません!!、どんな助けも認められるでしょう。

+0

私はあなたのコードを見ることができませんが、前に同じことに遭遇しました。f.fields_forの外にあるフィールドを追加するリンク/ボタンを置く必要があります:ギャラリー –

+0

こんにちは@ aldrien.h返信ありがとう、私私のコードでどこでもf.fields_forを使用していないので、私は自分の質問を編集し、コードを追加しました! – Pbms

+0

私はあなたが2つのループを持っていると思います。そのため、2回生成します。 –

答えて

1

これを試してください。

f.inputs 'Product Gallery' do 
     f.has_many :galleries do |c| 
     c.input :image, :hint => c.template.image_tag(c.object.image.url(:thumb)) 
     c.input :_destroy, :as => :boolean 
     end 
    end 

これはうまくいきます。

+0

@hgsongraにお返事ありがとうございます、私はこれを試しましたが運はありません。 – Pbms

関連する問題