update option and menu export csv single

This commit is contained in:
Aung Myo
2018-03-16 17:41:30 +06:30
parent f0e81caad0
commit e956b54886
14 changed files with 84 additions and 183 deletions

View File

@@ -33,27 +33,20 @@ class Menu < ApplicationRecord
end
def self.to_csv
m_attributes = %w{id name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
CSV.generate(headers: true) do |csv|
csv << m_attributes
menu = Menu.all
menu.each do |user|
puts user
csv << m_attributes.map{ |attr| user.send(attr)}
end
end
end
# mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
# CSV.generate(headers: true) do |csv|
# csv << m_attributes
# csv << mc_attributes
# MenuCategory.all.each do |user|
# puts user
# csv << mc_attributes.map{ |attr| user.send(attr)}
# end
# end
def self.import(file)
CSV.foreach(file.path, headers:true) do |row|
Menu.create! row.to_hash
end
end
end