Background
I have several models with approximately 40 attributes. They are normalized, simply that the models we are dealing with must have several attributes. In addition, this is a fairly standard application for rails 4.2 (update from rails 3.2). The application is used both to serve dynamic pages sprinkled with ajax calls, and for json, so they can be used by various json clients.
So, the call: http://example.com/products/1.json - returns json and http://example.com/products/1 returns haml-parsed view.
Problem
The JavaScript library I'm using (KendoUI) returns the entire record when updated, not just the updated fields. There is currently no way to avoid it if I don't want to rewrite the KendoUi Grid according to their support forum.
Thus, the user can search for all products, and I show her all the attributes of the product, and then, based on her access level, she can update certain fields (several points and price descriptions), however the ajax request contains ALL attributes, Thus, I I get ActiveModel :: ForbiddenAttributesError
Question
Part 1
How can I correctly (rails, so to speak) filter out the parameters that have been updated? I am currently doing a hash comparison @ product.attributes && & & params [: product] to find out if there are any updated / new attributes .. diff is deprecated from Rails 4.0.2
Part 2
My administrators are allowed to change almost all the attributes on these large models (except for timestamps, id and some others). What is the best way to do this and not do params [: product] .require (: base_cost) .permit (: vendor_cost ,: client_cost) for 30 odd attributes? It quickly becomes a problem to maintain these lists if the application is under development and attribute changes. I think I could use some CONSTANT - ALLOWED_ATTRIBUTES or ADMIN_ATTRIBUTES and USER_ATTRIBUTES, and pass this to allow. But something like un-Railsy?
source share