Ruby on rails Rails简单表单:为数组添加值
我有一个带有存储用户ID的数组列的模式。当用户单击特定按钮时,其id将添加到数组中。但是,当前,每次存储新id时,使用下面的代码只是替换已经存在的id。所以它只存储了1个idRuby 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
= 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