I want to pass conditional parameters based on selections (yes/no responses to 3 individual checkboxes) in the input form. I tried using the if then else approach but that is clearly not elegant due to 8 different options. Can someone please provide a better solution?
I came across the following post and tried my interpretation but could not figure out the correct answer.
Strong Parameters: How to permit parameters using conditions
Expected outcome: If a given checkbox is clicked that particular nested model gets updated / instance created, else not
My attempt at the parameters
def lapp_params
list_params_allowed = [:amount]
list_params_allowed += [:cond1_attributes[:name, :country]] if params[:lapp][:ind_var1]==1
list_params_allowed += [:cond2_attributes[:name,:course]] if params[:lapp][:ind_var2]==1
list_params_allowed += [:cond3_attributes[:name,:company]] if params[:lapp][:ind_var3]==1
params.require(:lapp).permit(list_params_allowed).merge(user_id: current_user.id)
end