accepts_nested_attributes_for rails 4 is not deleting

前端 未结 2 515
粉色の甜心
粉色の甜心 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
    
    0 讨论(0)
  • 2020-12-29 04:13

    The OP didn't have the same problem as me, but for anyone coming across this question, for me, it was the absence of allow_destroy: true as an argument on the accepts_nested_attributes call in the model.

    0 讨论(0)
提交回复
热议问题