Take the 2-minute tour ×

I upload/save mp3 files through Paperclip, it transforms the name with underscores when it saves it.

For example if I upload "Gould Stokowski 1.mp3" it saves into the the db as "Gould_Stokowski_1.mp3". How can I take out the underscores (replace them with spaces" when I retrieve the file and I want to display the name.

share|improve this question
I found this too which should be helpful. groups.google.com/group/ruby-talk-google/browse_thread/thread/… –  rordude Oct 15 '09 at 1:47

1 Answer 1

up vote 0 down vote accepted

What does the program do with the characters that started out as underscores? If it does nothing, then there is no way to go back using just the file name. The names don't "round trip."

If you're not concerned with that, then your question really has nothing to do with Paperclip or MP3 files at all. You just need to know how to change all the underscores into spaces. You can use String#tr for that:

$ irb
>> "Gould_Stokowski_1.mp3".tr('_', ' ')
=> "Gould Stokowski 1.mp3"
share|improve this answer
Ah! Sorry, any suggestion on how to remove the extension at the same time. –  rordude Oct 15 '09 at 1:28

Your Answer


