ruby-on-railsrubycollection-select

Collection_select not saving


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


Solution

  • This should work :

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