Is there a built in method similar to update_attributes that will ignore invalid keys in the hash passed in as parameter? If not, what’s the best way to deal with the situation where you are sent a hash which may or may not include valid keys?
Is there a built in method similar to update_attributes that will ignore invalid keys
Share
I’m not aware of anything that accomplishes this out of the box in Rails. I’m also not aware of a simple way to determine in general what a model’s “defined attributes” are—since a model may have overridden setters, virtual attributes, etc. Whenever I’ve needed this functionality, I’ve just explicitly defined a list of acceptable symbols in the class, something like this:
…and then used that later in some kind of filtering step: