gpt4 book ai didi

ruby-on-rails-4 - Rails 4 多嵌套表单和强参数

转载 作者:行者123 更新时间:2023-12-05 01:02:24 24 4
gpt4 key购买 nike

我正在使用 rails 4 和嵌套形式和强参数。

我需要从一种形式更新多个模型。

这就是我声明我的强参数的方式。从父 Controller 。
关联是has_many 和belongs_to 按照这个顺序运行Rundatum->Material->ParticleSize

def rundatum_params
params.require(:rundatum).permit( :material, :company_id, :material_density, :feed_moisture, :date, :building, :machine, :material_weight, :time_mins, :rate_lb_hr, :mill_amps, :class_amps, :mill_liner, :beater_plate_size, :mill_rpm, :class_rpm, :feeder_type, :feeder_setting, :feeder_aug_diameter, :tlgs_set, :air_pressure, :temp_mill_out, :temp_prod_out, :temp_ambient,

materials_attributes: [:id, :name, :density, :msds_url, :moisture, :notes, :_destroy],

particle_sizes_attributes: [:id, :screen, :percent_through, :percent_retained, :_destroy])
end

rails 服务器的输出是:
Rundatum Load (0.6ms)  SELECT  "rundata".* FROM "rundata"  WHERE "rundata"."id" = $1 LIMIT 1  [["id", 7]]

Unpermitted parameters: particle_sizes_attributes

从一种形式更新多个模型时,声明强参数的方法是什么?

谢谢

最佳答案

如果您有 ParticleSize嵌套在 Material ,那么你也应该嵌套你的参数。

def rundatum_params
params.require(:rundatum).permit( :material, :company_id, :material_density, :feed_moisture, :date, :building, :machine, :material_weight, :time_mins, :rate_lb_hr, :mill_amps, :class_amps, :mill_liner, :beater_plate_size, :mill_rpm, :class_rpm, :feeder_type, :feeder_setting, :feeder_aug_diameter, :tlgs_set, :air_pressure, :temp_mill_out, :temp_prod_out, :temp_ambient,

{ materials_attributes: [:id, :name, :density, :msds_url, :moisture, :notes, :_destroy,

{ particle_sizes_attributes: [:id, :screen, :percent_through, :percent_retained, :_destroy] }] })
end

关于ruby-on-rails-4 - Rails 4 多嵌套表单和强参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26722034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com