You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ruby On Rails参数许可后附加文件参数丢失问题求助

解决Rails参数许可后quotation_file丢失的问题

问题根源很明确:你把quotation_file的许可规则放在了body_attributes的定义里,但实际参数结构中,quotation_file是orders_attributes数组元素的直接子属性,并非嵌套在body_attributes下,所以当前的permit规则根本没包含这个参数,导致被过滤掉。

修正方案

直接将:quotation_file添加到@@ORDER_ATTRIBUTES数组中,因为它属于order层级的属性:

@@ORDER_ATTRIBUTES = [
  :id, :student_id, :user_id, :acceptance_letter_file,
  :arranged, :pickup, :notes, :order_type_id,
  :order_status_id, :quotation_file, # 新增这一行
  :body_attributes => @@BODY_ATTRIBUTES.values.union.flatten,
  :labels => []
]

为什么之前的写法无效?

看你提供的permit前参数结构:

orders_attributes数组里的元素直接包含quotation_file,和id、labels是同级的,而不是在body_attributes内部。但你之前把quotation_file: {}写在了@@BODY_ATTRIBUTES里,这意味着你只允许body_attributes下的quotation_file,但实际参数里的quotation_file不在这个路径下,自然会被permit过滤掉。

修正后重新执行permit操作,quotation_file就会被正确保留在许可后的参数中。

内容的提问来源于stack exchange,提问作者Drainer Channel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 13:57:31