Im working with a medium sized Rails application and I do this in every controller:
def create
@object = Model.new(params[:model].merge(editing_user: current_user))
...
end
def update
@object = Model.find(params[:id])
@object.editing_user = current_user
...
end
Setting the editing user over and over again is not DRY. I thought about cleaning this up with an observer but it would need access to the current user. Observers do not have access to the current user, neither should they (Law of Demeter).
Any suggestions how to DRY this up between controllers?
1 Answer