Open
Description
Hi,
Let's imagine we're using mogoid-history for History Tracking on Articles and also using devise which implements current_user for the controllers.
Every time we create a new article, we need to define the modifier explicitly, for example:
def create
@article = Article.create(params[:article].merge(modifier: current_user))
end
Now, every time we update an article, we need something similar to this:
def update
@article = Article.find(params[:id])
@article.update_attributes(params[:article]) # without merging current_user explicitly
end
The documentation says we don't need to define explicitly the modifier when updating attributes if we have the current_user available.
But looking at mongoid-history code itself, this is the before_create callback:
def before_create(track)
modifier_field = track.trackable.history_trackable_options[:modifier_field]
modifier = track.trackable.send modifier_field
track.modifier = current_user unless modifier # this condition will always prevent a different current_user if there's a modifier already defined from the model creation
end
Is this a bug, or am I missing something?