0
我使用Ruby Gems Faker,Populator在我的開發環境中創建虛假用戶列表。多種語言的Faker,Populator(英語和俄語)
在我的數據庫架構我有如下表
admin_customers
|- latin_first_name
|- latin_middle_name
|- latin_last_name
|- cyrillic_first_name
|- cyrillic_middle_name
|- cyrillic_last_name
這裏是我想如何將數據存儲針對每個字段的例子:
latin_first_name = "Viola"
latin_middle_name = "Lyagushkina"
latin_last_name = "Georgievna"
cyrillic_first_name = "Виола"
cyrillic_middle_name = "Люгашкина"
cyrillic_last_name = "Георгиевна"
這是我的populate.rake文件看起來像:
namespace :db do
desc "Create 100 customers"
task :populate => :environment do
require 'populator'
require 'faker'
Admin::Customer.destroy_all
Admin::Customer.populate 100 do |customer|
Faker::Config.locale = :ru
customer.cyrillic_first_name = Faker::Name.first_name
customer.cyrillic_middle_name = Faker::Name.last_name
customer.cyrillic_last_name = Faker::Name.last_name
Faker::Config.locale = :en
customer.latin_first_name = Faker::Name.first_name
customer.latin_middle_name = Faker::Name.last_name
customer.latin_last_name = Faker::Name.last_name
end
puts "created 100 users"
end
end
但是所有的數據都是以拉丁文生成的,你知道如何用Faker和Populator生成多種語言到單個記錄?