Hey, I''m using the attachment_fu plugin to upload images on the file system. To retrieve them I''m using: image = "/home/rajeev/Desktop/logo/logo/public#{icon.public_filename}" which is the same as: "/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/green_nature_on_white.jpg" Have can i do this in a shorter way by using RAILS_ROOT? I have tried this but no success. Would appreciate any help. Thanks Raj -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 24, 2007, at 11:14 AM, Rajeev Kala wrote:> Hey, > > I''m using the attachment_fu plugin to upload images on the file > system. > To retrieve them I''m using: > > image = "/home/rajeev/Desktop/logo/logo/public#{icon.public_filename}" > which is the same as: > > "/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/ > green_nature_on_white.jpg" > > > Have can i do this in a shorter way by using RAILS_ROOT? I have tried > this but no success. > > Would appreciate any help. > > Thanks > > RajTake your pick: image = File.join(RAILS_ROOT, "public#{icon.public_filename}") image = File.expand_path(''public'' + icon.public_filename, RAILS_ROOT) image = File.join(RAILS_ROOT, ''public'', icon.public_filename) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org
> Have can i do this in a shorter way by using RAILS_ROOT? I have tried > this but no success.just general fyi, but basically the RAILS_ROOT constant is a String object. you can use it any way you''d use a string RAILS_ROOT + "/some/string/" RAILS_ROOT.split(''/'') RAILS_ROOT.is_a?(String) # true ... hope this helps. :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Hey, Thanks for that it works perfect. Just got one question. When I run all 3 lines in the console i get: image = File.join(RAILS_ROOT, ''public'', icon.public_filename) "script/../config/../config/../public/icons/0000/0005/green_nature_on_white.jpg" image = File.expand_path(''public'' + icon.public_filename, RAILS_ROOT) "/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/green_nature_on_white.jpg" image = File.join(RAILS_ROOT, "public#{icon.public_filename}") "script/../config/../config/../public/icons/0000/0005/green_nature_on_white.jpg" Although they all work I don''t understand what the script/../config.... bit means? Cheers -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
On Oct 25, 2007, at 4:59 AM, Rajeev Kala wrote:> Hey, > > Thanks for that it works perfect. Just got one question. When I run > all > 3 lines in the console i get: > > image = File.join(RAILS_ROOT, ''public'', icon.public_filename) > "script/../config/../config/../public/icons/0000/0005/ > green_nature_on_white.jpg" > > image = File.expand_path(''public'' + icon.public_filename, RAILS_ROOT) > "/home/rajeev/Desktop/logo/logo/public/icons/0000/0005/ > green_nature_on_white.jpg" > > image = File.join(RAILS_ROOT, "public#{icon.public_filename}") > "script/../config/../config/../public/icons/0000/0005/ > green_nature_on_white.jpg" > > Although they all work I don''t understand what the script/../ > config.... > bit means? > > Cheers > --It means that RAILS_ROOT == ''script/../config/../config/..'' It also implies that the current directory is almost certainly the same as RAILS_ROOT because ''..'' means the parent directory so any ''foo/..'' means the foo subdirectory''s parrent -- the current directory. You can generally remove such constructs (there are some oddities that can happen with symbolic links that you can likely ignore in this case). -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---