Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TranslationImporter < ActiveRecordCsvImporter
- attr_accessor :locale
- validates_presence_of :locale, :message => 'is a required parameter'
- def validate_records
- csv_table.each do |row|
- record = ar_model.new(row.to_hash.merge(:locale => locale))
- errors.add(row[0], record.errors.full_messages) if !record.valid?
- end
- end
- def import!
- csv_table.each do |row|
- attrs = row.to_hash.merge(:locale => locale)
- Translation.update_or_create(attrs)
- end
- end
- def ar_model
- Translation
- end
- end
Add Comment
Please, Sign In to add comment