I have a web site that accesses Solr (a Lucene based search engine accessed via REST). I would like the configuration to be handled in the same was as database.yml. I envision a file called solr.yml that looks something like this in the config directory: development: url: http://dev.solr.example.com/search test: url: http://test.solr.example.com/search production: url: http://production.solr.example.com/search If I was to write this file how would I access it? Any pointers would be appreciated as it would aid testing and I have a couple of other projects that could use this technique. Thanks --~--~---------~--~----~------------~-------~--~----~ 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 could code it yourself, i think there is a railscast that shows an easy way to do it. or you could use one of the many plugins or gems out there. i just recently used http://github.com/binarylogic/settingslogic/tree/master On Jan 9, 9:32 am, Peter Hickman <pete...-XZoyATsUNX5Wk0Htik3J/w@public.gmane.org> wrote:> I have a web site that accesses Solr (a Lucene based search engine > accessed via REST). I would like the configuration to be handled in > the same was as database.yml. I envision a file called solr.yml that > looks something like this in the config directory: > > development: > url:http://dev.solr.example.com/search > > test: > url:http://test.solr.example.com/search > > production: > url:http://production.solr.example.com/search > > If I was to write this file how would I access it? > > Any pointers would be appreciated as it would aid testing and I have a > couple of other projects that could use this technique. > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can do solr_conf = open(''path/to/solr.yml'', ''r'') { |f| YAML.load(f) } solr_conf now holds a hash with your parameteres. You can access it simply by doing something like: url = solr_conf[RAILS_ENV][:url] On Jan 9, 11:33 am, scott <scot...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> you could code it yourself, i think there is a railscast that shows an > easy way to do it. or you could use one of the many plugins or gems > out there. i just recently usedhttp://github.com/binarylogic/settingslogic/tree/master > > On Jan 9, 9:32 am, Peter Hickman <pete...-XZoyATsUNX5Wk0Htik3J/w@public.gmane.org> wrote: > > > I have a web site that accesses Solr (a Lucene based search engine > > accessed via REST). I would like the configuration to be handled in > > the same was as database.yml. I envision a file called solr.yml that > > looks something like this in the config directory: > > > development: > > url:http://dev.solr.example.com/search > > > test: > > url:http://test.solr.example.com/search > > > production: > > url:http://production.solr.example.com/search > > > If I was to write this file how would I access it? > > > Any pointers would be appreciated as it would aid testing and I have a > > couple of other projects that could use this technique. > > > Thanks--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Peter On 9-Jan-09, at 11:44 AM, Harold wrote:> > You can do > > solr_conf = open(''path/to/solr.yml'', ''r'') { |f| YAML.load(f) } > > solr_conf now holds a hash with your parameteres. You can access it > simply by doing something like: > > url = solr_conf[RAILS_ENV][:url] > > On Jan 9, 11:33 am, scott <scot...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> you could code it yourself, i think there is a railscast that shows >> an >> easy way to do it. or you could use one of the many plugins or gems >> out there. i just recently usedhttp://github.com/binarylogic/settingslogic/tree/master >> >> On Jan 9, 9:32 am, Peter Hickman <pete...-XZoyATsUNX5Wk0Htik3J/w@public.gmane.org> wrote: >> >>> I have a web site that accesses Solr (a Lucene based search engine >>> accessed via REST). I would like the configuration to be handled in >>> the same was as database.yml. I envision a file called solr.yml that >>> looks something like this in the config directory: >> >>> development: >>> url:http://dev.solr.example.com/search >> >>> test: >>> url:http://test.solr.example.com/search >> >>> production: >>> url:http://production.solr.example.com/search >> >>> If I was to write this file how would I access it? >> >>> Any pointers would be appreciated as it would aid testing and I >>> have a >>> couple of other projects that could use this technique. >>If you take this approach, you can also embed erb in your yaml, and get a nice little object with your config at hand: require ''ostruct'' raw_config = File.read("#{RAILS_ROOT}/config/config.yml") erb_config = ERB.new(raw_config).result config = YAML.load(erb_config)[RAILS_ENV] HomestarsConfig = OpenStruct.new(config) so if you had a config setting of mail_server, you could access it HomestarsConfig.mail_server J --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Scott Nj wrote:> you could code it yourself, i think there is a railscast that shows an > easy way to do it. or you could use one of the many plugins or gems > out there. i just recently used > http://github.com/binarylogic/settingslogic/tree/masterYes, I believe there is a railscast on showing just what you''re looking for: http://railscasts.com/episodes/85-yaml-configuration-file -- 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 -~----------~----~----~----~------~----~------~--~---
Thanks to everyone who replied. The railscast is just what I wanted. Thanks to you all again. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---