For stuff like database or S3 credentials which we don't want to hard-code in config, you can use environment variables (for example) on production, but not development, eg:
config/app/production.rb App.configure do config.paypal_api_username = ENV['PAYPAL_USERNAME'] config.paypal_api_password = ENV['PAYPAL_PASSWORD'] config.paypal_api_signature = ENV['PAYPAL_SIGNATURE'] end config/app/development.rb App.configure do config.paypal_api_username = 'test_user' config.paypal_api_password = 'test_ pass' config.paypal_api_signature = 'test_sig' endThen you can reference App.paypal_api_username in your code, and environment differences look after themselves. You'll still end up with ERB in your database.yml though, so this might not be what you're after.
Cheers
Mike Bailey <mailto:[email protected]> 29 July 2012 3:48 PM Thanks for posting example Michael. When and how are you setting the environment variable? - Mike Sent from my iPhoneOn 29/07/2012, at 11:55 AM, Michael Pearson <[email protected] <mailto:[email protected]>> wrote:--You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.To post to this group, send email to [email protected].To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.Michael Pearson <mailto:[email protected]> 29 July 2012 1:55 PMNot what I meant - that's controlling individual the database connection of individual models. It could be used, I guess, to override the connection mechanism to use something other than database.yml, but that too seems inelegant (eg, it won't work with the Delayed Job implied model)As an example, here's what I've got as an interim YAML / ERB based solution:https://gist.github.com/3195668 -- Michael Pearson --You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.To post to this group, send email to [email protected].To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.Mark Ratjens <mailto:[email protected]> 29 July 2012 1:43 PMIn the first Rails Recipes book by Chad Fowler, there's a recipe called Connecting to Multiple Databases. I seem to remember using something like it circa 2006, but can;t lay my hands on the code (it was in a private repo of a company that was eventually bought out).Just a little snippet from the recipe to give some clues: class External < ActiveRecord::Base self.abstract_class = true establish_connection :products end class Product < External end class TaxConversion < External end -- *Mark Ratjens* *Co-founder, Habanero Software* * * Sydney, Australia [email protected] <mailto:[email protected]> @MarkRatjens <mailto:[email protected]> www.habanerohq.com <http://habanerohq.com> +61 414 159 357 --You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.To post to this group, send email to [email protected].To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.Michael Pearson <mailto:[email protected]> 29 July 2012 1:28 PM Hi,Lincoln Stoll recently gave a presentation about the 12 Factor App at DevOps Melbourne. One of the take-homes from that presentation for me was the idea of using URIs in environment variables to configure environment-specific (vs app specific) parts of the application: http://www.12factor.net/configFor instance, it'd be nice if I could have on my system: DATABASE_URI=mysql://foo:bar@localhost/myDatabaseAnd then keep application specific database config (eg, my locale) to the database.yml.I'm wondering if anybody has implemented this already in a gem, or a gist, or similar. It's relatively trivial to use ERB to do this in your database.yml right now, but seems inelegant.Also, I hate ERB. Just putting that out there. -- Michael Pearson --You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.To post to this group, send email to [email protected].To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
-- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
<<inline: compose-unknown-contact.jpg>>
<<inline: postbox-contact.jpg>>
<<inline: postbox-contact.jpg>>
