0

I have a page with 10 checkboxes that translate into true/false based on the user selection at the moment my strong param method looks like

def checkbox_params
    params.require(:"{}").permit(:param1, :param2, :param3,...)
end

based on this I iterate over each value and check if it is true/false before I commit the information to my database. If in the future I will add more params this list will become big and I will have a long for iteration. Is there a better practice to pass this information?

Thank you

Quantico
  • 2,398
  • 7
  • 35
  • 59

1 Answers1

1

You can use an array of check boxes so you only end up with 1 param to permit.

Rails will take each checked value and then append it to an array which ends up being the value of the param. Then you can just .each through the array and do your comparisons there.

AntelopeSalad
  • 1,736
  • 1
  • 16
  • 27
  • can you pass an array in strong params? – Quantico Dec 03 '13 at 01:10
  • http://stackoverflow.com/questions/16549382/how-to-permit-an-array-with-strong-parameters I guess you can. I will accept you answer in the next few minutes – Quantico Dec 03 '13 at 01:13
  • Can strong-params take a regexp, such as `/^check\d+/`? or am I being a newb bc I haven't read about them or used them yet. – Phlip Dec 03 '13 at 01:17