Permanent database of rubies on rails

This is more a logical question than anything else.

I want to create a database (model) in ruby ​​on rails that contains information that I do not want to delete when I reset the database. I also want the information stored in this database to be automatically transferred to production when I click on my project.

I have googled, but have not found anything relevant, and I feel that I am missing something obvious. How to do it?

Thanks in advance for your help!

+4
source share
2 answers

You can seed the database with data. Using db / seeds.rb plus rake db: seed

According to official documentation

Rails has a 'seeds' feature that should be used for seeding a database with initial data. It a really simple feature: just fill up db/seeds.rb with some Ruby code, and run rake db:seed:
5.times do |i|
  Product.create(name: "Product ##{i}", description: "A product.")
end

This is generally a much cleaner way to set up the database of a blank application.

http://edgeguides.rubyonrails.org/migrations.html#migrations-and-seed-data

, , , .

, seeds.rb . Ruby, . , XML-.

+4

rails_config

seeds, jamesw, ( yml), .

secrets.yml Rails 4.1, , . rails-config:

#app/settings.yml
option:
  setting: "value"
  setting2: "value"

( - ..), Settings.option.setting:

enter image description here

+2

Source: https://habr.com/ru/post/1543499/


All Articles