Class: Faq

Inherits:
ApplicationRecord show all
Defined in:
app/models/faq.rb

Overview

Schema Information

Table name: faqs

id             :bigint           not null, primary key
description_en :text(65535)      not null
description_th :text(65535)      not null
icon           :string(191)
order          :integer          default(0), not null
title_en       :string(191)      not null
title_th       :string(191)      not null
type           :integer
created_at     :datetime         not null
updated_at     :datetime         not null

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

sync_carrierwave_url

Class Method Details

.import(file_path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/faq.rb', line 32

def self.import(file_path)
  csv_text = File.read(file_path)
  rows = CSV.parse(csv_text, headers: true)

  rows.each do |row|
    faq = Faq.new(
      title_th: row['Title_th'],
      title_en: row['Title_en'],
      description_th: row['Description_th'],
      description_en: row['Description_en']
    )

    unless faq.save
      APMErrorHandler.report("Import FAQ failed, title: #{faq.title_en}", message: faq.error.full_messages.to_sentence)
    end
  end
end

Instance Method Details

#descriptionObject



28
29
30
# File 'app/models/faq.rb', line 28

def description
  send("description_#{I18n.locale}".to_sym)
end

#titleObject



24
25
26
# File 'app/models/faq.rb', line 24

def title
  send("title_#{I18n.locale}".to_sym)
end