Hi all, I was wondering if there was a kosher way of getting the complete path to the root location of a Rails app? I know there''s ROOT_PATH, but I think that changes when I do Dir.chdir() to some other location. Or at least it''s what I am seeing. For example:>> Dir.pwd=> "/Users/diego/Code/Rails/mview">> puts RAILS_ROOTscript/../config/../config/.. => nil>> Dir.chdir(''/'')=> 0>> puts RAILS_ROOTscript/../config/../config/.. => nil>> Dir.pwd=> "/" So basically anytime I do a chdir, away from the Rails root dir, I can no longer use RAILS_ROOT to get a starting point to do file and directory work. Do I just need to define a global const with my app''s complete path and use that? Cheers, Diego --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I suppose it depends on what context you need the root for. One way that always seems to work is to ask for File.dir(__FILE__) Scott On 2/7/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I was wondering if there was a kosher way of getting the complete path > to the root location of a Rails app? I know there''s ROOT_PATH, but I > think that changes when I do Dir.chdir() to some other location. Or at > least it''s what I am seeing. > > For example: > > >> Dir.pwd > => "/Users/diego/Code/Rails/mview" > >> puts RAILS_ROOT > script/../config/../config/.. > => nil > >> Dir.chdir(''/'') > => 0 > >> puts RAILS_ROOT > script/../config/../config/.. > => nil > >> Dir.pwd > => "/" > > So basically anytime I do a chdir, away from the Rails root dir, I can > no longer use RAILS_ROOT to get a starting point to do file and > directory work. > > Do I just need to define a global const with my app''s complete path > and use that? > > Cheers, > Diego > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Sorry. File.dirname(__FILE__) On 2/7/07, Scott Taylor <smtlaissezfaire-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I suppose it depends on what context you need the root for. One way > that always seems to work is to ask for File.dir(__FILE__) > > Scott > > > On 2/7/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I was wondering if there was a kosher way of getting the complete path > > to the root location of a Rails app? I know there''s ROOT_PATH, but I > > think that changes when I do Dir.chdir() to some other location. Or at > > least it''s what I am seeing. > > > > For example: > > > > >> Dir.pwd > > => "/Users/diego/Code/Rails/mview" > > >> puts RAILS_ROOT > > script/../config/../config/.. > > => nil > > >> Dir.chdir(''/'') > > => 0 > > >> puts RAILS_ROOT > > script/../config/../config/.. > > => nil > > >> Dir.pwd > > => "/" > > > > So basically anytime I do a chdir, away from the Rails root dir, I can > > no longer use RAILS_ROOT to get a starting point to do file and > > directory work. > > > > Do I just need to define a global const with my app''s complete path > > and use that? > > > > Cheers, > > Diego > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, Scott. I want the root as a starting point from which I can (for example) store uploaded files somewhere in my application''s directory structure. I may want to get to: /Users/diego/MyApp/public/data/images So I wanted to have a way to always get /Users/diego/MyApp/ and I can go off from there. Thanks for the tip on using __FILE__. What I did, before your reply, was to add APP_ROOT = File.expand_path(RAILS_ROOT) in the application''s initialization. Diego On Feb 8, 10:49 am, "Scott Taylor" <smtlaissezfa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sorry. File.dirname(__FILE__) > > On 2/7/07, Scott Taylor <smtlaissezfa...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I suppose it depends on what context you need the root for. One way > > that always seems to work is to ask for File.dir(__FILE__) > > > Scott > > > On 2/7/07, Diego <dbar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I was wondering if there was a kosher way of getting the complete path > > > to the root location of a Rails app? I know there''s ROOT_PATH, but I > > > think that changes when I do Dir.chdir() to some other location. Or at > > > least it''s what I am seeing. > > > > For example: > > > > >> Dir.pwd > > > => "/Users/diego/Code/Rails/mview" > > > >> puts RAILS_ROOT > > > script/../config/../config/.. > > > => nil > > > >> Dir.chdir(''/'') > > > => 0 > > > >> puts RAILS_ROOT > > > script/../config/../config/.. > > > => nil > > > >> Dir.pwd > > > => "/" > > > > So basically anytime I do a chdir, away from the Rails root dir, I can > > > no longer use RAILS_ROOT to get a starting point to do file and > > > directory work. > > > > Do I just need to define a global const with my app''s complete path > > > and use that? > > > > Cheers, > > > Diego--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---