Hi, I''d like to be able to set a variable for each environment I have. It''s a path to a folder that''s different on each system: development and production. I then, need to be able to read it from my controller. How can I do this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, I''d like to be able to set a variable for each environment I have. It''s a path to a folder that''s different on each system: development and production. I then, need to be able to read it from my controller. How can I do this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can set it in application_controller.rb like this
case ENV[''RAILS_ENV'']
when ''production'' : var = ''foo''
when ''development'' : var = ''bar''
...etc
end
eggie5 wrote:> Hi,
>
> I''d like to be able to set a variable for each environment I have.
> It''s a path to a folder that''s different on each system:
development
> and production. I then, need to be able to read it from my controller.
>
> How can I do this?
>
>
> >
>
--
Sincerely,
William Pratt
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
One slight mistake, thats controllers/application.rb not application_controller.rb. William Pratt wrote:> You can set it in application_controller.rb like this > > case ENV[''RAILS_ENV''] > when ''production'' : var = ''foo'' > when ''development'' : var = ''bar'' > ...etc > end > > > > eggie5 wrote: > >> Hi, >> >> I''d like to be able to set a variable for each environment I have. >> It''s a path to a folder that''s different on each system: development >> and production. I then, need to be able to read it from my controller. >> >> How can I do this? >> >> >> >> >> > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 put the exact code you wrote in my controllers/application.rb file,
then tried to access var on my other controller and it won''t work.:
logger.info "***** var is : #{var}"
undefined local variable or method `var'' for #<PrivateController:
0x3525be0>
On Sep 13, 4:07 pm, William Pratt
<bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org>
wrote:> One slight mistake, thats controllers/application.rb not
> application_controller.rb.
>
>
>
> William Pratt wrote:
> > You can set it in application_controller.rb like this
>
> > case ENV[''RAILS_ENV'']
> > when ''production'' : var =
''foo''
> > when ''development'' : var =
''bar''
> > ...etc
> > end
>
> > eggie5 wrote:
>
> >> Hi,
>
> >> I''d like to be able to set a variable for each
environment I have.
> >> It''s a path to a folder that''s different on each
system: development
> >> and production. I then, need to be able to read it from my
controller.
>
> >> How can I do this?
>
> --
> Sincerely,
>
> William Pratt
--~--~---------~--~----~------------~-------~--~----~
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, I should have been more specific:
case ENV[''RAILS_ENV'']
when ''production'' : @var = ''foo''
when ''development'' : @var = ''bar''
end
You need to make the variable an instance variable. Sorry, long day and
I was getting lazy.
eggie5 wrote:> I put the exact code you wrote in my controllers/application.rb file,
> then tried to access var on my other controller and it won''t
work.:
>
> logger.info "***** var is : #{var}"
>
>
> undefined local variable or method `var'' for
#<PrivateController:
> 0x3525be0>
>
> On Sep 13, 4:07 pm, William Pratt
<bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:
>
>> One slight mistake, thats controllers/application.rb not
>> application_controller.rb.
>>
>>
>>
>> William Pratt wrote:
>>
>>> You can set it in application_controller.rb like this
>>>
>>> case ENV[''RAILS_ENV'']
>>> when ''production'' : var =
''foo''
>>> when ''development'' : var =
''bar''
>>> ...etc
>>> end
>>>
>>> eggie5 wrote:
>>>
>>>> Hi,
>>>>
>>>> I''d like to be able to set a variable for each
environment I have.
>>>> It''s a path to a folder that''s different on
each system: development
>>>> and production. I then, need to be able to read it from my
controller.
>>>>
>>>> How can I do this?
>>>>
>> --
>> Sincerely,
>>
>> William Pratt
>>
>
>
> >
>
--
Sincerely,
William Pratt
--~--~---------~--~----~------------~-------~--~----~
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, I am really not paying attention...if you want to access this from another controller other than ApplicationController, you need to make it a class variable like @@var. William Pratt wrote:> sorry, I should have been more specific: > case ENV[''RAILS_ENV''] > when ''production'' : @var = ''foo'' > when ''development'' : @var = ''bar'' > end > > You need to make the variable an instance variable. Sorry, long day > and I was getting lazy. > > eggie5 wrote: >> I put the exact code you wrote in my controllers/application.rb file, >> then tried to access var on my other controller and it won''t work.: >> >> logger.info "***** var is : #{var}" >> >> >> undefined local variable or method `var'' for #<PrivateController: >> 0x3525be0> >> >> On Sep 13, 4:07 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: >> >>> One slight mistake, thats controllers/application.rb not >>> application_controller.rb. >>> >>> >>> >>> William Pratt wrote: >>> >>>> You can set it in application_controller.rb like this >>>> >>>> case ENV[''RAILS_ENV''] >>>> when ''production'' : var = ''foo'' >>>> when ''development'' : var = ''bar'' >>>> ...etc >>>> end >>>> >>>> eggie5 wrote: >>>> >>>>> Hi, >>>>> >>>>> I''d like to be able to set a variable for each environment I have. >>>>> It''s a path to a folder that''s different on each system: development >>>>> and production. I then, need to be able to read it from my controller. >>>>> >>>>> How can I do this? >>>>> >>> -- >>> Sincerely, >>> >>> William Pratt >>> >> >> >> >> > > -- > Sincerely, > > William Pratt > > > >-- Sincerely, William Pratt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Will I be able to access this form a model? On Sep 13, 4:52 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote:> Sorry, I am really not paying attention...if you want to access this > from another controller other than ApplicationController, you need to > make it a class variable like @@var. > > > > William Pratt wrote: > > sorry, I should have been more specific: > > case ENV[''RAILS_ENV''] > > when ''production'' : @var = ''foo'' > > when ''development'' : @var = ''bar'' > > end > > > You need to make the variable an instance variable. Sorry, long day > > and I was getting lazy. > > > eggie5 wrote: > >> I put the exact code you wrote in my controllers/application.rb file, > >> then tried to access var on my other controller and it won''t work.: > > >> logger.info "***** var is : #{var}" > > >> undefined local variable or method `var'' for #<PrivateController: > >> 0x3525be0> > > >> On Sep 13, 4:07 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > > >>> One slight mistake, thats controllers/application.rb not > >>> application_controller.rb. > > >>> William Pratt wrote: > > >>>> You can set it in application_controller.rb like this > > >>>> case ENV[''RAILS_ENV''] > >>>> when ''production'' : var = ''foo'' > >>>> when ''development'' : var = ''bar'' > >>>> ...etc > >>>> end > > >>>> eggie5 wrote: > > >>>>> Hi, > > >>>>> I''d like to be able to set a variable for each environment I have. > >>>>> It''s a path to a folder that''s different on each system: development > >>>>> and production. I then, need to be able to read it from my controller. > > >>>>> How can I do this? > > >>> -- > >>> Sincerely, > > >>> William Pratt > > > -- > > Sincerely, > > > William Pratt > > -- > Sincerely, > > William Pratt--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> Will I be able to access this form a model?No. You could create a constant instead of a instance/class var by adding this into your config/environments/development.rb: SOME_VAR = "foo" SOME_VAR.freeze Then in production.rb do the same, but set it to something else.> > On Sep 13, 4:52 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: >> Sorry, I am really not paying attention...if you want to access this >> from another controller other than ApplicationController, you need to >> make it a class variable like @@var. >> >> >> >> William Pratt wrote: >>> sorry, I should have been more specific: >>> case ENV[''RAILS_ENV''] >>> when ''production'' : @var = ''foo'' >>> when ''development'' : @var = ''bar'' >>> end >> >>> You need to make the variable an instance variable. Sorry, long day >>> and I was getting lazy. >> >>> eggie5 wrote: >>>> I put the exact code you wrote in my controllers/application.rb file, >>>> then tried to access var on my other controller and it won''t work.: >> >>>> logger.info "***** var is : #{var}" >> >>>> undefined local variable or method `var'' for #<PrivateController: >>>> 0x3525be0> >> >>>> On Sep 13, 4:07 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: >> >>>>> One slight mistake, thats controllers/application.rb not >>>>> application_controller.rb. >> >>>>> William Pratt wrote: >> >>>>>> You can set it in application_controller.rb like this >> >>>>>> case ENV[''RAILS_ENV''] >>>>>> when ''production'' : var = ''foo'' >>>>>> when ''development'' : var = ''bar'' >>>>>> ...etc >>>>>> end >> >>>>>> eggie5 wrote: >> >>>>>>> Hi, >> >>>>>>> I''d like to be able to set a variable for each environment I have. >>>>>>> It''s a path to a folder that''s different on each system: development >>>>>>> and production. I then, need to be able to read it from my controller. >> >>>>>>> How can I do this? >> >>>>> -- >>>>> Sincerely, >> >>>>> William Pratt >> >>> -- >>> Sincerely, >> >>> William Pratt >> >> -- >> Sincerely, >> >> William Pratt > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
what does the .freeze do? On Sep 13, 8:55 pm, Philip Hallstrom <ra...-SUcgGwS4C16SUMMaM/qcSw@public.gmane.org> wrote:> > Will I be able to access this form a model? > > No. > > You could create a constant instead of a instance/class var by adding this > into your config/environments/development.rb: > > SOME_VAR = "foo" > SOME_VAR.freeze > > Then in production.rb do the same, but set it to something else. > > > > > On Sep 13, 4:52 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > >> Sorry, I am really not paying attention...if you want to access this > >> from another controller other than ApplicationController, you need to > >> make it a class variable like @@var. > > >> William Pratt wrote: > >>> sorry, I should have been more specific: > >>> case ENV[''RAILS_ENV''] > >>> when ''production'' : @var = ''foo'' > >>> when ''development'' : @var = ''bar'' > >>> end > > >>> You need to make the variable an instance variable. Sorry, long day > >>> and I was getting lazy. > > >>> eggie5 wrote: > >>>> I put the exact code you wrote in my controllers/application.rb file, > >>>> then tried to access var on my other controller and it won''t work.: > > >>>> logger.info "***** var is : #{var}" > > >>>> undefined local variable or method `var'' for #<PrivateController: > >>>> 0x3525be0> > > >>>> On Sep 13, 4:07 pm, William Pratt <bi...-YbheRAKfYF4eIZ0/mPfg9Q@public.gmane.org> wrote: > > >>>>> One slight mistake, thats controllers/application.rb not > >>>>> application_controller.rb. > > >>>>> William Pratt wrote: > > >>>>>> You can set it in application_controller.rb like this > > >>>>>> case ENV[''RAILS_ENV''] > >>>>>> when ''production'' : var = ''foo'' > >>>>>> when ''development'' : var = ''bar'' > >>>>>> ...etc > >>>>>> end > > >>>>>> eggie5 wrote: > > >>>>>>> Hi, > > >>>>>>> I''d like to be able to set a variable for each environment I have. > >>>>>>> It''s a path to a folder that''s different on each system: development > >>>>>>> and production. I then, need to be able to read it from my controller. > > >>>>>>> How can I do this? > > >>>>> -- > >>>>> Sincerely, > > >>>>> William Pratt > > >>> -- > >>> Sincerely, > > >>> William Pratt > > >> -- > >> Sincerely, > > >> William Pratt--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---