M.T Davis M.T Davis - 4 months ago 19
Ruby Question

Ruby on Rails SyntaxError using Strong Parms

I'm trying to whitelist mhealth_ids in /app/controllers/clients_controller.rb as displayed below.

def client_params
params.require(:client).permit(:firstName, :lastName, :dob, :gender_id, :remove_image, :rh_options, :insurance_id, :state_id, :ed_id, :wk_id, :grade_id, :rsource_id, :image, :race_id, :employment_id, :comments, :email, :phone, :address, :city, :state, :zipcode, :name, rhealth_ids:[], :name, mhealth_ids:[])
end


I'm using the same syntax as
:name, rhealth_ids:[]
which works fine when
:name, mhealth_ids:[]
isn't inserted.

I'm not sure what I'm missing. I'm sure it's something small.

Answer

This is the correct syntax for the original question.

 def client_params
      params.require(:client).permit(:firstName,  :lastName,:dob, :gender_id, :remove_image, :rh_options, :insurance_id, :state_id, :ed_id, :wk_id, :grade_id, :rsource_id, :image, :race_id, :employment_id, :comments, :email, :phone, :address, :city, :state, :zipcode, :name, rhealth_ids:[], mhealth_ids:[])
 end

Both rhealth_ids and mhealth_ids have to go at the end of Ruby.