Collection_select not saving

流过昼夜 提交于 2019-12-12 05:15:56

问题


I'm trying to implement a collection select to create associations between my model group and user (join table: groups_user). But this association is not saving when i'm using a collection_select. And I have absolutely no idea what can be the problem

My code :

view :

<%= simple_form_for(group, remote: true) do |f| %>

  <%= f.collection_select :user_ids, @users.order(:pseudo), :id, :pseudo, {}, {multiple: true} %>

  <%= f.submit %>

<% end %>

& my controller(group) :

def group_params
  params.require(:group).permit(:name, :user_ids)
end

Just for info, i have a action to submit individually the association, and it's working perfectly ! But when i try to implement a collection to select collectively, is not working


回答1:


This should work :

def group_params
  params.require(:group).permit(:name, :user_ids => [])
end


来源:https://stackoverflow.com/questions/44015135/collection-select-not-saving

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!