大家好。
我正在我的 Rails 5 应用程序中创建一个日志进程,位于application controller
. 我在那里创建是因为我想在许多具有before_save
属性的控制器中调用日志进程。日志将保存用户在form
on中执行的更改edit view template
。问题是我进不去<ObjectController:>
里面application controller
。我已经instance variable
从控制器中获得了,但我也需要ObjectController
,因为我必须strong parameters
从控制器对象中获得。保存用户在输入字段中插入的strong parameters
所有数据。
这是我已经做过的:
应用程序/控制器/应用程序控制器
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
因此,我需要获取控制器对象来访问强参数,以便比较用户是否编辑了任何数据。我不确定这是否是最好的方法/做法。如果有更好的方法,我想知道。但是我需要在大量需要数据日志的控制器中调用这个过程。
谢谢你的时间,对不起任何不好的英语..