Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- encoding : utf-8 -*-
- class Country < ActiveRecord::Base
- translates :name
- globalize_accessors :en, :fr
- def self.import
- I18n.available_locales.each do |l|
- File.open("public/countries.#{I18n.locale}.txt", "r") do |file|
- I18n.locale = l.to_sym
- file.each_line do |line|
- name, code = line.split(";")
- data = {:name => name, :code => code}
- puts "name = #{name} code = #{code}"
- uncached do
- if !Country.exists?(:code => code)
- c = Country.create(data)
- puts "id of country = #{c.id}"
- else
- puts "Need to update an existing record."
- end
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement