Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6985997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:45:09+00:00 2026-05-27T18:45:09+00:00

I am using seed.rb to populate both my development and production database. I usually

  • 0

I am using seed.rb to populate both my development and production database. I usually populate the first with dummy data and the latter with the real minimal data that my app needs to run (e.g. the first user and so on).

How can I specify in seed.rb for what environment each data is?

Given that I know “group” to be a Gemfile method, I’d like to achieve the same behavior for seed.rb.

E.g. I’d like to write something like this in my seed.rb:

group :development do 
  # development specific seeding code
end

group :production do 
  # production specific seeding code
end

# non-specific seeding code (it always runs) 

This to be able to call both the development-specific and the non-specific code with

$ rake db:seed

And to call both the production-specific and the non-specific code with:

$ rake db:seed RAILS_ENV=production 

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:45:10+00:00Added an answer on May 27, 2026 at 6:45 pm

    seeds.rb is just a plain ruby file, so there are several ways you could approach this. How about a case statement?

    # do common stuff here
    
    case Rails.env
    when "development"
       ...
    when "production"
       ...
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to populate my production database app with data in particular tables. This
I have a rake task to seed an application with random data using the
I'm using Development Seed's fantastic Context module (version 6.x-2.0) for Drupal 6 on a
We installed Seed Fu to add in seed data in rails, then noticed that
I am using seeds.rb to populate some State model reference data: State.create :name =>
Previously I used a database initializer to seed or pre-populate my tables when creating
I,m using Globalize2. I'd like to populate DB with db:seed for different locales: en,
I'm trying to insert some sample data (Seed data) using EF 4.3 Migration. The
I'm using this code snippet to encrypt/decrypt data in my app's database: http://www.androidsnippets.com/encryptdecrypt-strings It
I have been using the spreadsheet gem from http://spreadsheet.ch/ to read in seed data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.