I made this Query
MtDispositivo.where("id_conta = 28 or id_conta = 29 or id_conta = 30 or id_conta = 36")
This Query returns all the accounts that contain the IDs: 28, 29, 30 and 36.
Could you give me a hint of how I perform the code in Ruby so that it is exported from SQL to Excel and performed Download?
I did so:
> require 'csv' CSV.generate do |csv| csv <<
> ["headers","describing","the data"] mysql.query("MtDispositivo.where
> "id_conta = 28 or id_conta = 29 or id_conta = 30 or id_conta = 36).each { |row| csv << row }
end
Is that correct?
Updated:
I was able to create the Ruby code snippet.
def mt_dispositivo_xls
mt_dispositivo = MtDispositivo.where("id_conta = 28 or id_conta = 29 or id_conta = 30 or id_conta = 36")
send_data mt_dispositivo.to_xls(:except => [:id_conta]), content_type 'application/vnd.ms-excel', filename: 'mt_dispositivo_xls'
end
I'm just having this syntax error when writing in Console.
send_mt_dispositivo.to_xls(:except => [:id_conta]), content_type 'application/vnd.ms-excel', filename: 'mt_dispositivo_xls'
SyntaxError: unexpected ',', expecting end-of-input
...to_xls(:except => [:id_conta]), content_type 'application/vn...
Can you help me with this?