1
I made this Query
MtDispositivo.where("id_conta = 28 or id_conta = 29 or id_conta = 30 or id_conta = 36")
This Query returns me all accounts containing the Ids: 28, 29, 30 and 36.
Could you give me a hint on how to 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
That is correct?
Updated:
I was able to create the code snippet in Ruby.
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
Only I’m having this Syntax error when text in the 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?