jump to navigation

Rails environment file “inheritance” December 15, 2007

Posted by John Dewey in Code, Configuration, Example, Rails.

Wouldn’t it be nice if  Rails could inherit behavior from a given environment file? Here is a DRY approach when adding new environments:

Add the following to your new environment file:

eval File.read("#{RAILS_ROOT}/..../production.rb")


1. reidmix - December 20, 2007

That’s cool — it’s almost like including an .h file in c/c++. I wonder if this includes the bad stuff like recursion — in that case you might need to wrap the eval in an:
if not definded? PRODUCTION_RB

2. truc-machin-bidule - December 12, 2013

I think using load is much better:

load Rails.root.join(‘config/environments/production.rb’)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: