In my Ruby application, I have a file upload that I've set up with AWS. When displaying uploaded files back to the user, I would like to display only the name of the uploaded file, not the entire file.
In my view, I'm using:
<td>
<%= link_to file.file_url.split('/').last, file.file_url, target: '_blank' %>
</td>
Which outputs something like File_name.pdf instead of https://bucket_name.s3-us-west.../file_name.pdf, which is exactly what I need.
However, for certain file uploads, there are parameters appended to the file name, so I get something like File_name.pdf?AWSAccessKeyID=1234&Expires=1234. When displayed in a view, that looks ugly as hell.
I would like to split file URL string at the last trailing slash, and then again at the "?". I've tried slash and chomp but can't seem to format it correctly. Is that the appropriate approach?