2011-12-22 7 views
0

私はnested_attributesの追加と削除にnested_formを使用しています。添付を追加入れ子のフォームの削除が機能しない

class Text < ActiveRecord::Base 
    attr_accessible :attachments_attributes 
    has_many :attachments, :as => :attachable 
    accepts_nested_attributes_for :attachments 
end 

とネストされたモデル

class Attachment < ActiveRecord::Base 
    attr_accessible :description, :file 
    belongs_to :attachable, :polymorphic => true 
end 

が正常に動作しますが、doesentを削除します。

text[attachments_attributes][0][_destroy]入力値がfalseから1に変更されたので、これは問題ではないと思います。

私の更新方法:

def update 
    @text = Text.find(params[:id]) 
    if @text.update_attributes(params[:text]) 
     redirect_to @text, :notice => "Successfully updated text." 
    else 
     render :action => 'edit' 
    end 
    end 

私の更新方法でのparamsの出力は

attachments_attributes: 
    '0': 
    description: asdf asdf as fs 
    _destroy: '1' 
    id: '2' 
    '1': 
    description: '' 
    _destroy: '1' 
    id: '3' 
    '2': 
    description: asdsadasd 
    _destroy: '1' 
    id: '4' 

である私は、問題を見つけることができませんので、あなたは間違っていただきましたアイデアを持っていますか?

ありがとうございました! 不明な点がある場合は、コメントを残してください。

答えて

関連する問題