Rename a file before saving with Paperclip

I was recently trying to rename a file before having it saved by Paperclip. As it was not obivous to me, I would like to share the solution with you.

In the model file with the paperclip "definitions", let's add:

before_post_process :rename_file

and (in my case, the paperclip attachement name is "file")

def rename_file
  self.file.instance_write :file_name, function_to_change_a_string(file_file_name)

And it should work. Easy once found :-)