Rails converts empty arrays into nils in params of the request

后端 未结 6 1796
闹比i
闹比i 2021-02-01 12:20

I have a Backbone model in my app which is not a typical flat object, it\'s a large nested object and we store the nested parts in TEXT columns in a MySQL database.

I wa

6条回答
  •  有刺的猬
    2021-02-01 12:45

    I ran into a similar issue and found out that passing an array with an empty string would be processed correctly by Rails, as mentioned above. If you encounter this while submitting a form, you might want to include an empty hidden field that matches the array param :

    
    

    When the actual param is empty the controller will always see an array with an empty string, thus keeping the submission stateless.

提交回复
热议问题