I've built some in-line editing features using AJAX that allows a user to update lots of small bits of information on the page, and constructs JS to update the page afterwards. This same logic should handle tens of different mini-forms containing different attributes or sets of attributes (like firstname & lastname). In most cases, the value being changed is the same as the value to update on the page, so it's easy to write a Jquery call to update content accordingly. However sometimes I want to override what will be updated: for example, when a user changes their zipcode, their city and state should be displayed afterwards as well.
In these cases, I can add a form element to indicate what fields should be updated on the page. But the controller logic gets complicated when I consider security. I don't want a user to be able to change that form element to display any of their attributes; rather, I'd like to check whether a given attribute is in the whitelist of attributes they can update (strong parameters style), then use that information to decide whether the controller allows that attribute to be displayed on the page.
The strong parameters setup doesn't seem to allow for this. I can check whether a parameter is present in user_params, but if I'm not actually submitting a new value for that attribute via the params hash, it's treated as absent from user_params.
Is there any way to check whether an attribute is "on the whitelist", ie. would be accepted into user_params, even if we're not attempting to change it?
Or alternatively, is there another way you'd approach this need?