Renaming uploaded files

Wait. I’m not quite sure what you’re trying to do. Is it to change the name people see in the posts in which they’re uploaded? If that’s the case, then maybe you want to do something like

rake posts:remap["old-name.pdf","newname.pdf"]

As described in Replace a string in all posts. I think that for your purposes the original filename in the Upload model doesn’t really matter.

But you can change that with

u=Upload.find_by(original_filename: 'mypretty-w9.pdf')

I tried rebaking a post with that upload and nothing happened.


def rename_upload(old_name, new_name)
  u=Upload.find_by(original_filename: old_name)

If you paste that, then you can


It’ll fix it so that the downloads get the better filename.

In my former life as an academic I had my specific way of naming my PDFs that was different from anyone else’s; I’m pretty sure that my wife has her own. My guess is that no one will like your filenames even when you get them “right”. :wink: