Rails converts empty arrays into nils in params of the request

后端 未结 6 1800
闹比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:42

    Looks like this is a known, recently introduced issue: https://github.com/rails/rails/issues/8832

    If you know where the empty array will be you could always params[:...][:...] ||= [] in a before filter.

    Alternatively you could modify your BackBone model's to JSON method, explicitly stringifying the nested_json value using JSON.stringify() before it gets posted and manually parsing it back out using JSON.parse in a before_filter.

    Ugly, but it'll work.

提交回复
热议问题