URL from file path

What’s the best way to get the URL for a
resource when my ruby code has the full pathname. I want to turn
/var/rails/project/public/images/image.png into /images/image.png

you could use File.basename to return just the filename then prepend
with '/images/'

Have you tried something like:

resource_path.slice("#{ File.expand_path(RAILS_ROOT) }/public".length,
resource_path.length)

There's probably a much better way!

Matt

thanks, that’s the one. previously I was
using Pathname.new(".").realpath to get the rails root, but that seemed
to have problems under windows.

Matthew Denner wrote: