Today I Learned

hashrocket A Hashrocket project

Permitting array attributes in Rails

If you want to permit an attribute that is an array, your controller should have something like this.

permitted_params = params.require(:person).permit(:name, :age, sibling_names: [])

Take a look at the sibling_names: [] attribute, the empty array tells Rails to permit an attribute of the array class to come through the params.

Looking for help? Hashrocket has been an industry leader in Ruby on Rails since 2008. Rails is a core skill for each developer at Hashrocket, and we'd love to take a look at your project. Contact us and find out how we can help you.