Export from SQL to Excel and perform SyntaxError error: unexpected ',', expecting end-of-input

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 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?

    
asked by anonymous 30.06.2015 / 18:54

1 answer

0

It does not seem to be a problem in the query, looking at the documentation of send_data I suppose I've missed : , change this:

send_data mt_dispositivo.to_xls(:except => [:id_conta]), content_type 'application/vnd.ms-excel', filename: 'mt_dispositivo_xls'

For this

send_data mt_dispositivo.to_xls(:except => [:id_conta]), content_type: 'application/vnd.ms-excel', filename: 'mt_dispositivo_xls'

However maybe content_type is some older version, apparently today (rails 5.1.1) is only type , so use:

send_data mt_dispositivo.to_xls(:except => [:id_conta]), type: 'application/vnd.ms-excel', filename: 'mt_dispositivo_xls'

Documentation: link

    
17.05.2017 / 19:31