Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails简单表单:为数组添加值_Ruby On Rails_Arrays_Simple Form - Fatal编程技术网

Ruby on rails Rails简单表单:为数组添加值

Ruby on rails Rails简单表单:为数组添加值,ruby-on-rails,arrays,simple-form,Ruby On Rails,Arrays,Simple Form,我有一个带有存储用户ID的数组列的模式。当用户单击特定按钮时,其id将添加到数组中。但是,当前,每次存储新id时,使用下面的代码只是替换已经存在的id。所以它只存储了1个id = simple_form_for @post, html: { multipart: true } do |f| =f.hidden_field :volunteers_ids, value: current_user.id, multiple: true =f.button :submit 其他相关代码: d

我有一个带有存储用户ID的数组列的模式。当用户单击特定按钮时,其id将添加到数组中。但是,当前,每次存储新id时,使用下面的代码只是替换已经存在的id。所以它只存储了1个id

= simple_form_for @post, html: { multipart: true } do |f|
  =f.hidden_field :volunteers_ids, value: current_user.id, multiple: true
  =f.button :submit
其他相关代码:

def post_params
  params.require(:post).permit(:volunteers_ids => [])
end
迁移:

def change
  add_column :posts, :volunteers_id, :string, array: true, default: []
end