Hi all, I was wondering where the best place is to put global values, such as consts? Is environment.rb a good (and kosher) place? Or should I place them in the ApplicationHelper, some custom global helper, or other? When I said semi-global I guess I was referring to strings, const ints, etc. which may be shared between two or more controller/views. I''m guessing in this scenario placing them in a helper is the best solution? Thoughts? Thanks. 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 -~----------~----~----~----~------~----~------~--~---
Hi! On Feb 13, 6:04 pm, "Diego" <dbar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I was wondering where the best place is to put global values, such as > consts? Is environment.rb a good (and kosher) place? Or should I place > them in the ApplicationHelper, some custom global helper, or other? > > When I said semi-global I guess I was referring to strings, const > ints, etc. which may be shared between two or more controller/views. > I''m guessing in this scenario placing them in a helper is the best > solution?environment.rb is a good start. --~--~---------~--~----~------------~-------~--~----~ 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 2/14/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I was wondering where the best place is to put global values, such as > consts? Is environment.rb a good (and kosher) place? Or should I place > them in the ApplicationHelper, some custom global helper, or other? > > When I said semi-global I guess I was referring to strings, const > ints, etc. which may be shared between two or more controller/views. > I''m guessing in this scenario placing them in a helper is the best > solution? > > Thoughts? >Have a read here: http://toolmantim.com/article/2006/12/27/environments_and_the_rails_initialisation_process The various config hooks are a pretty good place for global stuff. For the "semi-global" case, I normally create a module named after my app and place these things in there, with defaults. I can then override defaults in environment.rb. Cheers, --max --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ball, Donald A Jr \(Library\)
2007-Feb-13 23:26 UTC
Re: Best place for global (or semi-global) constants.
I rather like the AppConfig plugin for this: http://jarmark.org/projects/app-config/ - donald --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamal Soueidan
2007-Feb-13 23:35 UTC
Re: Best place for global (or semi-global) constants.
Ball, Donald A Jr (Library) wrote:> I rather like the AppConfig plugin for this: > > http://jarmark.org/projects/app-config/ > > - donaldI still don''t see the big difference between AppConfig and the database.yml? -- 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 Feb 13, 2007, at 6:26 PM, Ball, Donald A Jr ((Library)) wrote:> > I rather like the AppConfig plugin for this: > > http://jarmark.org/projects/app-config/ >What benefits does this plugin provide beside the implicit namespace? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> > Thoughts? > >I put all global stuff in (of course) config/environment.rb. These are the settings that are consistent across dev, test and production environments. I then have a config/constants.rb that are application specific and may be modified as features are added/modified. I load it by adding the following line in config/envrionment.rb: require File.join(File.dirname(__FILE__), ''constants'') I ignore the environment.rb from the svn repository so it doesn''t get updated and therefore won''t be overridden with an svn update. Some items such as an ENCRYPTION_SALT constant would be different on a test box than the production box and should go in environment.rb. Production may also be running a different RAILS_GEM_VERSION, so we wouldn''t want to accidentally update that setting. Other application constants and some methods on those constants I put in constants.rb. I add them here because no manual work needs to be done to update the environment.rb. And the application gets these updates with a deploy. It''s a simple solution that has worked and I haven''t had any issues. Hope this helps, andy -- Andrew Stone --~--~---------~--~----~------------~-------~--~----~ 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 2/13/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi all, > > I was wondering where the best place is to put global values, such as > consts? Is environment.rb a good (and kosher) place? Or should I place > them in the ApplicationHelper, some custom global helper, or other? > > When I said semi-global I guess I was referring to strings, const > ints, etc. which may be shared between two or more controller/views. > I''m guessing in this scenario placing them in a helper is the best > solution? > > Thoughts? > > Thanks. > > Cheers, > Diego >Diego, I find it clearer to namespace my application constants in environment.rb. # environment.rb ... module COOL_APP VERSION = 1.1 end Then in your application: COOL_APP::VERSION -- Zack Chandler http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
We also use environment.rb On Feb 14, 12:04 am, "Diego" <dbar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > > I was wondering where the best place is to put global values, such as > consts? Is environment.rb a good (and kosher) place? Or should I place > them in the ApplicationHelper, some custom global helper, or other? > > When I said semi-global I guess I was referring to strings, const > ints, etc. which may be shared between two or more controller/views. > I''m guessing in this scenario placing them in a helper is the best > solution? > > Thoughts? > > Thanks. > > 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 -~----------~----~----~----~------~----~------~--~---
Russell Norris
2007-Feb-17 16:09 UTC
Re: Best place for global (or semi-global) constants.
I second the namespacing in config/environment.rb. That added level of safety that the module gives helps me sleep at night knowing I won''t be breaking Rails'' code or that of any plugins/gems/etc. Provided I create a unique module name and not something like Rails. ;) RSL On 2/13/07, Zack Chandler <zackchandler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > On 2/13/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > Hi all, > > > > I was wondering where the best place is to put global values, such as > > consts? Is environment.rb a good (and kosher) place? Or should I place > > them in the ApplicationHelper, some custom global helper, or other? > > > > When I said semi-global I guess I was referring to strings, const > > ints, etc. which may be shared between two or more controller/views. > > I''m guessing in this scenario placing them in a helper is the best > > solution? > > > > Thoughts? > > > > Thanks. > > > > Cheers, > > Diego > > > > Diego, > > I find it clearer to namespace my application constants in environment.rb. > > # environment.rb > ... > module COOL_APP > VERSION = 1.1 > end > > Then in your application: > > COOL_APP::VERSION > > -- > Zack Chandler > http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
I use an app_name.rb in lib/ contaning: module AppName CONSTANT = 1 end On 17/02/07, Russell Norris <sconds-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I second the namespacing in config/environment.rb. That added level of > safety that the module gives helps me sleep at night knowing I won''t be > breaking Rails'' code or that of any plugins/gems/etc. Provided I create a > unique module name and not something like Rails. ;) > > RSL > > On 2/13/07, Zack Chandler <zackchandler-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > On 2/13/07, Diego <dbarros-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Hi all, > > > > > > I was wondering where the best place is to put global values, such as > > > consts? Is environment.rb a good (and kosher) place? Or should I place > > > them in the ApplicationHelper, some custom global helper, or other? > > > > > > When I said semi-global I guess I was referring to strings, const > > > ints, etc. which may be shared between two or more controller/views. > > > I''m guessing in this scenario placing them in a helper is the best > > > solution? > > > > > > Thoughts? > > > > > > Thanks. > > > > > > Cheers, > > > Diego > > > > > > > Diego, > > > > I find it clearer to namespace my application constants in > > environment.rb. > > > > # environment.rb > > ... > > module COOL_APP > > VERSION = 1.1 > > end > > > > Then in your application: > > > > COOL_APP::VERSION > > > > -- > > Zack Chandler > > http://depixelate.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 -~----------~----~----~----~------~----~------~--~---
> Hi all, > > I was wondering where the best place is to put global values, such as > consts? Is environment.rb a good (and kosher) place? Or should I place > them in the ApplicationHelper, some custom global helper, or other?Adding them to an active-record-model that is loaded when it''s requested is also an idea, which I use myself... With a class-method you can get the class from the db, and pass on the method-call: --- # Passes requests on to the object below # def self.method_missing(method, *args) GlobalConfig.find(:first).send(method, *args) end --- greetings, Wybo Wiersma -- ::Student: - History, Informatiekunde (computer linguistics, IR, webtech) and Philosophy - Member of the Center for Metahistory Groningen (http://www.rug.nl/let/cmg) ::Free Software and Open Source Developer: - http://www.LogiLogi.org, Cumulative, shared commenting, publication and idea sharing: Where insight comes together... - ComLinToo, a computational linguistics toolset written in Perl - Lake (LogiLogi.org Make), a make-replacement using makefiles in pure C++ ::Being: - In the world, wavy hair, go figure (http://nl.logilogi.org/HomE/WyboWiersma) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---