jeudi 29 octobre 2015

Possible oneliner for this Ruby on Rails code

I have a file object which is of type Rails ActionDispatch::Http::UploadedFile.

I need to overwrite user assigned filename with a generic name while preserving the extension of the file. This is how I have the code implemented currently. Is there are a way better and elegant way of writing this in Ruby.

extension = File.extname(file_name.original_filename)
file_name.original_filename = "hello#{extension}"

Aucun commentaire:

Enregistrer un commentaire