Hello people.
I'm creating a log process in my Rails 5 application, inside the application controller
. I'm creating there because I want to call the log process inside many controllers with a before_save
property. The log will save the changes that user performs in the form
on edit view template
. The problem is that I can't get the <ObjectController:>
inside application controller
. I've already got the instance variable
from the controller, but I need the ObjectController
too, because I have to get the strong parameters
from controller object. The strong parameters
holds all data that user inserted on input fields.
This is what I've done already:
app/controllers/application controller
def log
@controlr = instance_variable_get("@#{controller_name.singularize}") #get the edited object
attribs = @controlr.attribute_names #get object table column names
edited_data = controlr_params #stuck here!
ctrlr = @controlr.attributes #retrive object data from db
...
##compare the edited_data with the actual data from db and check if something was changed
end
So, I need to obtain the Controller Object to access the strong parameters in order to compare if user edited any data. I'm not sure if this is the best way/practice to do this. If there is a better way, I'd like to know. But I need to call this process in a great number of controllers that require a data log.
Thanks for you time and sorry any bad english..