LoginSignup
1
1

More than 5 years have passed since last update.

seed データで、productionとdevelopmentで反映させたいデータが異なる時

Last updated at Posted at 2016-04-21

productionとdevelopmentで反映させたいデータが異なる時

やや無理やりなところがありますが、migrationファイルに直書きという手法をとることで解決できました

db/migrate/20160225054555_hoge.rb
class Hoges < ActiveRecord::Migration
  def change
    create_table :hoges do |t|
      t.string :title, null: false
      t.text :description, null: false
      t.string :image, null: false

      t.timestamps null: false
    end
  end
end
hogehogecategories = HogehogeCategory.create (
  [
    {
      name: "hoge1"
    },
    {
      name: "hoge2"
    },
    {
      name: "hoge3"
    },
  ]
)

このようにすることで、今はカテゴリをproductionにもdevelopmentでも反映させることができ、
もしdevelopmentのみにしたい時はseedに入れたら反映されます( ^ ^ )/■

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1