Rails – Strong parameters with empty arrays

This is quite late, but I just had this problem myself. I solved it by including both the scalar version and array version in the permit statement, like so:

params.require(:photo).permit(:tags, tags: [])

FYI – it has to have both in the same permit statement – if you chain them it’ll get thrown out for some reason.

EDIT: I just noticed that an empty array submitted via this method will be turned into nil – I’ve now got a bunch of fields that should be empty arrays that are nil. So the solution I posted doesn’t actually work for me.

EDIT the second: Thought I had already added this, but this problem is related to Rails performing deep_munge on params hashes. This comment explains how to fix it: https://stackoverflow.com/a/25428800/130592

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)