Guest User

Untitled

a guest
May 28th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. class TranslationImporter < ActiveRecordCsvImporter
  2. attr_accessor :locale
  3.  
  4. validates_presence_of :locale, :message => 'is a required parameter'
  5.  
  6. def validate_records
  7. csv_table.each do |row|
  8. record = ar_model.new(row.to_hash.merge(:locale => locale))
  9. errors.add(row[0], record.errors.full_messages) if !record.valid?
  10. end
  11. end
  12.  
  13. def import!
  14. csv_table.each do |row|
  15. attrs = row.to_hash.merge(:locale => locale)
  16. Translation.update_or_create(attrs)
  17. end
  18. end
  19.  
  20. def ar_model
  21. Translation
  22. end
  23.  
  24. end
Add Comment
Please, Sign In to add comment