# Environment Specific Data

**URL:** <https://www.ruby-forum.com/t/environment-specific-data/121336>\
**Category:** Rails\
**Created:** [November 26, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/environment-specific-data/121336 "2007-11-26T23:58:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Deck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@Mike\_Deck](https://www.ruby-forum.com/u/Mike_Deck)\
**Post date:** [November 26, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/environment-specific-data/121336/1 "2007-11-26T23:58:41Z")

</div>

I’m trying to figure out the best way to manage multiple sets of data  
across different environments. I have a situation where I want to  
automatically load some dummy data into my development environment but  
I do not want that data to be loaded when I deploy to production. I  
would imagine that this is a relatively common situation and I’m  
wondering what people consider to be the best practice for dealing  
with this type of issue.

My latest idea is to simply create data only migrations for my dev  
data and just wrap the entire body of the up method with with an --if  
RAILS\_ENV == ‘development’-- This will probably work fine for my  
needs, but it seems a little hacky and the Agile Web Dev w/ Rails book  
actually specifically warns against using migrations to load data not  
intended for production (even though they don’t follow their own  
advice in the example app) so I’m thinking there’s got to be a better  
way or at least some existing convention for dealing with this  
problem.

Any ideas or tips would be much appreciated.

Thanks in advance.

-Mike

---

<div class="post-metadata">

**Author:** ![Mike\_Deck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@Mike\_Deck](https://www.ruby-forum.com/u/Mike_Deck)\
**Post date:** [November 27, 2007, 10:47am UTC](https://www.ruby-forum.com/t/environment-specific-data/121336/2 "2007-11-27T10:47:31Z")

</div>

you could probably use the same trick in the fixtures.

\<% if RAILS\_ENV == ‘development’ then %\>  
…  
\<% end %\>

---

<div class="post-metadata">

**Author:** ![Mike\_Deck](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@Mike\_Deck](https://www.ruby-forum.com/u/Mike_Deck)\
**Post date:** [November 27, 2007, 4:54pm UTC](https://www.ruby-forum.com/t/environment-specific-data/121336/3 "2007-11-27T16:54:06Z")

</div>

I’ve mentioned this on a similar thread… I find Rake tasks to be  
especially  
valuable for setting up a database.

In lib/tasks, create a file called import.rake. In there, do something  
like

namespace :db do

namespace :development do

```
desc "bootstraps the dev database"
task :import => :environment do

  User.create :login=>"admin", :password=>"1234",

```

:password\_confirmation=\>“1234”, :email=\>removed\_email\_address@domain.invalid  
Product.create :name=\>“Widget”, :price=\>15.99, :url=\>  
[http://www.foo.com/widget.jpg](http://www.foo.com/widget.jpg)

```
end

```

end # end development namespace

end # end db namespace

So then

rake db:development:import

That’s a really simple approach. You could get a little more  
sophistcated  
with Rake though and determine what to do based on the environment. This  
is  
verbose to show you some possibilities.

Hope that helps!

On Nov 27, 2007 3:47 AM, Thorsten M.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
