strong parameters not accepting array

后端 未结 3 689
深忆病人
深忆病人 2021-01-02 00:51

I have this in my view which is a multiselect checkbox

Model

class User < ActiveRecord::Base
  has_many :user_roles, :dependent =         


        
3条回答
  •  伪装坚强ぢ
    2021-01-02 01:52

    Answering myself, I got it working not directly, but the below method from the Strong Parameters issues discussion helped me in converting a normal parameter to a whitelisted one.

    def user_params
      params.require(:user).permit(:first_name).tap do |whitelisted|
        whitelisted[:role_ids] = params[:user][:role_ids]
      end
    end
    

提交回复
热议问题