Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
21
Help us understand the problem. What is going on with this article?
@kimihito_

環境ごとに投入する初期データを変える

More than 3 years have passed since last update.

やりたいこと

初期データを db/seeds.rb に書いているが、Rails.envに応じて投入するデータを変えたい。

やったこと

  1. db/seeds/development.rb のような db/seedsディレクトリを作成してその中に環境名.rbのファイルを生成する

  2. db/seeds.rb に下記の内容を入れる

db/seeds.rb
load(Rails.root.join('db', 'seeds', "#{Rails.env.downcase}.rb"))

これで、 rake db:seed RAILS_ENV=developmentdb/seeds/development.rbに記載している初期データが入るようになります。

参考

Ruby On Rails: way to create different seeds file for environments - Stack Overflow

21
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
kimihito_
株式会社ミノタケというひとりぼっちの会社でRailsやらなんやらを書いています。

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
21
Help us understand the problem. What is going on with this article?