Split your database seeds.rb by Rails environment

18-Aug-2023 926
The seeds.rb file in a Ruby on Rails app can be a double-edged sword.On one hand, it's very useful! The seeds.rb file makes it easy to pre-populate your database with data for development or production. Unfortunately though, since each Ruby on Rails app only has a single seeds.rb file, it can quickly get cluttered. Plus, there's bound to be data you want to seed in production, but not development (or vice-versa).That's where this article comes in! This short guide will show you how split your seeds.rb file into 3 separate files, one for each Rails environment.This will help you organise your database seeds better, and let you seed data for development without cluttering your production app.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle