允许属性的不允许参数错误 [英] Unpermitted parameters error for permitted attributes
本文介绍了允许属性的不允许参数错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 rails应用,用于进行编辑传递工作人员ID移位控制器..
I have a rails app for doing volunteer scheduling. Shifts have multiple workers. I am trying to pass the worker ids from the edit form to the shifts controller.
正在使用适当的元素生成输入表单:
The input form is being generated with the appropriate elements:
<select id="shift_workers" multiple="multiple" name="shift[workers][]">
<option selected="selected" value="1">username</option>
</select>
在控制器中,我有以下代码:
In the controller I have the following code:
def shift_params
params.require(:shift).permit(:start, :end, :size, :task_id, workers: [])
end
尽管如此,编辑班次时出现以下错误:
Despite this I am getting the following error when editing shifts:
Unpermitted parameters: workers
推荐答案
您必须执行以下操作:
workers_ids: []
而不是:
workers: []
因为数据库存储的是工作程序ID的数组,而不是工作程序的数组.
because the database stores an array of the worker ids, not an array of workers.
这篇关于允许属性的不允许参数错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文