Twinfriends Twinfriends - 9 months ago 47
Ruby Question

Remove first part of a string that haven't fixed length

I ran into some problems with my code and I don't know how to fix it. So my problem:

On a View of my application, there is a filepath displayed like this:


But I only want the filename as Output, means:


How can i achieve this? I tried with several options like
etc, but it doesn't work, since the number after "attachment" is increased by 1 for every single upload. At beginning I thought about to simply remove 2 chars, don't matter what they are. But then i ran into another problem that happens when the 100 file is uploaded. In this case i would have to remove 3 chars instead of 2, and i'm again at the beginning of my problem.

May someone of you can help me?

Thanks a lot!

Answer Source

If I understand your question right, then, maybe it should help you:

a = "/resume/attachment/12/yaml_error_complete.yml"
#=> "yaml_error_complete.yml"