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 -- *Jeremy Wells* Serval Systems Ltd. www.servalsystems.co.uk <http://www.servalsystems.co.uk> Tel: 01342 331940 Fax: 01342 331950 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
you could use File.basename to return just the filename then prepend with ''/images/'' On 8/25/06, Jeremy Wells <jwells-cH1Rxhrj+4a/3pe1ocb+s/XRex20P6io@public.gmane.org> wrote:> > 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 > > > -- > > > Jeremy Wells > Serval Systems Ltd. > > www.servalsystems.co.uk > Tel: 01342 331940 > Fax: 01342 331950 > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 8/25/06, Jeremy Wells <jwells-cH1Rxhrj+4a/3pe1ocb+s/XRex20P6io@public.gmane.org> wrote:> > 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.pngHave 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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:> On 8/25/06, Jeremy Wells <jwells-cH1Rxhrj+4a/3pe1ocb+s/XRex20P6io@public.gmane.org> wrote: > >> 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 >> > > 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 > > > >-- *Jeremy Wells* Serval Systems Ltd. www.servalsystems.co.uk <http://www.servalsystems.co.uk> Tel: 01342 331940 Fax: 01342 331950 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---