accepts_nested_attributes_for rails 4 is not deleting

前端 未结 2 535
粉色の甜心
粉色の甜心 2020-12-29 03:29

I have been reading and researching for about 3 days now. This is my last resort.

land.rb:

has_many :uploads , :dependent => :destroy
accepts_nest         


        
2条回答
  •  情书的邮戳
    2020-12-29 03:59

    You need to allow the :_destroy parameter for your nested model as well, as this gets used when you check the 'Delete' checkbox in the form. It's Rails' way of flagging model instances that have to be destroyed.

    def land_params  
      params.require(:land).permit(uploads_attributes: [:id, :filename, :_destroy])
    end
    

提交回复
热议问题