Greg Hauptmann
2007-Feb-10 22:45 UTC
accessing a Custom variable I put in development.rb - how can I do this?
Hi, I just quite seem to find out how to access a custom environment variable I put into "development.rb", "test.rb" etc Can someone give me a pointer for this please. Tks Greg --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-11 08:16 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
(bump) Still trying to understand default Rails behavior here so would be great if someone can clarify. That is how is one supposed to put one''s own custom variables in the environment.rb/developmnet.rb type files and then get access to them. In the environment.rb file the last line is "# Include your application configuration below". However I''ve tried adding my own variables here and not been able to see them later within ENV. That is: a) add the following to the bottom of environment.rb gregs.test1="1*************************************************" b) go "ruby script/console" c) issue "ENV" but I can''t see this custom environment variable being loaded. Can any clarify the default means of setting custom environment variables in rails (I''ve been googling but to no avail yet) Tks Greg On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I just quite seem to find out how to access a custom environment variable > I put into "development.rb", "test.rb" etc > > Can someone give me a pointer for this please. > > Tks > Greg >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
George Ogata
2007-Feb-11 08:57 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> (bump) > > Still trying to understand default Rails behavior here so would be great if > someone can clarify. That is how is one supposed to put one''s own custom > variables in the environment.rb/developmnet.rb type files and then get > access to them. > > In the environment.rb file the last line is "# Include your application > configuration below". However I''ve tried adding my own variables here and > not been able to see them later within ENV. That is: > > a) add the following to the bottom of environment.rb > > gregs.test1="1*************************************************"Hi Greg, To define an environment variable, use ENV[''NAME''] = value (where value must be a string). So doing ENV[''test1''] = ''blah'' works for me. Regards, George. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-11 10:41 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
Tks George - but do you/someone else know whether it is possible to put your environment variables directly within the rails environment files? (e.g. environment.rb, development.rb etc) Greg On 2/11/07, George Ogata <george.ogata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > (bump) > > > > Still trying to understand default Rails behavior here so would be great > if > > someone can clarify. That is how is one supposed to put one''s own > custom > > variables in the environment.rb/developmnet.rb type files and then get > > access to them. > > > > In the environment.rb file the last line is "# Include your application > > configuration below". However I''ve tried adding my own variables here > and > > not been able to see them later within ENV. That is: > > > > a) add the following to the bottom of environment.rb > > > > gregs.test1="1*************************************************" > > Hi Greg, > > To define an environment variable, use ENV[''NAME''] = value (where > value must be a string). > > So doing ENV[''test1''] = ''blah'' works for me. > > Regards, > George. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
George Ogata
2007-Feb-11 11:25 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Tks George - but do you/someone else know whether it is possible to put your > environment variables directly within the rails environment files? (e.g. > environment.rb, development.rb etc) > > GregYes, it works for me if I stick it in environment.rb or environments/development.rb, on a fresh rails app, in both rails 1.1.6 and 1.2.2. Note that you must assign a String. A Fixnum, etc. won''t cut it (you should see an error when you start script/console if you get this wrong). Is there a reason you need environment variable, BTW? Because it might be easier to just use a constant, e.g., "FOO = 1", as well. Cheers, George. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
George Ogata
2007-Feb-11 11:29 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
On 2/11/07, George Ogata <george.ogata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Tks George - but do you/someone else know whether it is possible to put your > > environment variables directly within the rails environment files? (e.g. > > environment.rb, development.rb etc) > > > > Greg > > Yes, it works for me if I stick it in environment.rb or > environments/development.rb, on a fresh rails app, in both rails 1.1.6 > and 1.2.2. Note that you must assign a String. A Fixnum, etc. won''t > cut it (you should see an error when you start script/console if you > get this wrong). > > Is there a reason you need environment variable, BTW? Because it > might be easier to just use a constant, e.g., "FOO = 1", as well.I should also add that my experiments were on Linux. I''m not sure if other OSs might behave differently.> Cheers, > George.--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-11 20:46 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
basically wanted a mechanism to have a external URL used by the application to be different in development George. Are you putting your entry in environment.rb right at the bottom of the file, i.e. outside the Rails:: Initializer.run area? I''m assuming that after I have put, myvar = ''this is it'', at the bottom of the environment.rb file and restart, that if I go "ruby script/console" then ENV I should be able to see it, or ENV[''myvar''].....but at this stage this isn''t working for me. I''m on Mac OS X. Any ideas why this isn''t working George/anyone? Thanks again Greg On 2/11/07, George Ogata <george.ogata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 2/11/07, George Ogata <george.ogata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Tks George - but do you/someone else know whether it is possible to > put your > > > environment variables directly within the rails environment files? ( > e.g. > > > environment.rb, development.rb etc) > > > > > > Greg > > > > Yes, it works for me if I stick it in environment.rb or > > environments/development.rb, on a fresh rails app, in both rails 1.1.6 > > and 1.2.2. Note that you must assign a String. A Fixnum, etc. won''t > > cut it (you should see an error when you start script/console if you > > get this wrong). > > > > Is there a reason you need environment variable, BTW? Because it > > might be easier to just use a constant, e.g., "FOO = 1", as well. > > I should also add that my experiments were on Linux. I''m not sure if > other OSs might behave differently. > > > Cheers, > > George. > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Greg Hauptmann
2007-Feb-11 21:19 UTC
Re: accessing a Custom variable I put in development.rb - how can I do this?
doh! saw the errors of my ways - had been treating the environment.rb like a java properties file - I see now it''s actually ruby and I had to put the "ENV[''myvar'']=...." into the file, not "''myvar'' = ''...''" - thanks George On 2/12/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > basically wanted a mechanism to have a external URL used by the > application to be different in development George. Are you putting your > entry in environment.rb right at the bottom of the file, i.e. outside the > Rails::Initializer.run area? > > I''m assuming that after I have put, myvar = ''this is it'', at the bottom of > the environment.rb file and restart, that if I go "ruby script/console" > then ENV I should be able to see it, or ENV[''myvar''].....but at this stage > this isn''t working for me. I''m on Mac OS X. > > Any ideas why this isn''t working George/anyone? > > Thanks again > Greg > > > > > On 2/11/07, George Ogata < george.ogata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On 2/11/07, George Ogata < george.ogata-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On 2/11/07, Greg Hauptmann <greg.hauptmann.ruby-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Tks George - but do you/someone else know whether it is possible to > > put your > > > > environment variables directly within the rails environment > > files? (e.g. > > > > environment.rb, development.rb etc) > > > > > > > > Greg > > > > > > Yes, it works for me if I stick it in environment.rb or > > > environments/development.rb, on a fresh rails app, in both rails 1.1.6 > > > and 1.2.2. Note that you must assign a String. A Fixnum, etc. won''t > > > cut it (you should see an error when you start script/console if you > > > get this wrong). > > > > > > Is there a reason you need environment variable, BTW? Because it > > > might be easier to just use a constant, e.g., "FOO = 1", as well. > > > > I should also add that my experiments were on Linux. I''m not sure if > > other OSs might behave differently. > > > > > Cheers, > > > George. > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Alex Wayne
2007-Feb-12 00:28 UTC
Re: accessing a Custom variable I put in development.rb - ho
Greg Hauptmann wrote:> basically wanted a mechanism to have a external URL used by the > application > to be different in development George. Are you putting your entry in > environment.rb right at the bottom of the file, i.e. outside the Rails:: > Initializer.run area? > > I''m assuming that after I have put, myvar = ''this is it'', at the bottom > of > the environment.rb file and restart, that if I go "ruby script/console" > then > ENV I should be able to see it, or ENV[''myvar''].....but at this stage > this > isn''t working for me. I''m on Mac OS X. > > Any ideas why this isn''t working George/anyone? > > Thanks again > GregI''m glad you got it working, but I don''t think this is the best way to handle this. As stated above, you should probably use a constant, or perhaps a direct manipulation of the url to be changed. Lets say you have some API class that you want to use a different URL in development mode. The cleanest way to handle this is something like #development.rb MyApi.access_url = "http://foo.com" That section is for manipulating parts of your app more than setting ENV variables. -- 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 -~----------~----~----~----~------~----~------~--~---