2013-02-11 11 views
11

sto avendo problemi con metodo Rails: send_datarotaie non SEND_DATA in formato

Ecco la mia azione:

def export 
    send_data(current_user.contacts.to_csv, 
    type: 'text/csv; charset=utf-8; header=present', 
    disposition: 'attachment; filename=contacts.csv' 
) 
end 

Questo non promt per un download, ma solo rendere il risultato sul schermo. Ho provato entrambi i server pow e thin.

Non riesco a capire cosa sto facendo male?

sto usando rails 4.0.0.beta

EDIT:

intestazioni CURL:

< HTTP/1.1 200 OK 
< X-Frame-Options: SAMEORIGIN 
< X-XSS-Protection: 1; mode=block 
< X-Content-Type-Options: nosniff 
< X-UA-Compatible: chrome=1 
< X-XHR-Current-Location: /contacts/export 
< Content-Disposition: attachment; filename=contacts.csv 
< Content-Transfer-Encoding: binary 
< Content-Type: text/csv; charset=utf-8; header=present 
< Cache-Control: private 
< ETag: "48d3d8bd1c8d25cafb82ab705e4875ab" 
< Set-Cookie: request_method=GET; path=/ 
< X-Request-Id: c2588883-f3f9-4f68-8a8c-0de758c47288 
< X-Runtime: 0.185206 
< Connection: close 
< Server: thin 1.5.0 codename Knife 
+0

Potresti postare il risultato di 'arricciare -v http: // localhost: 3000/whateveryourrouteis'? Scommetto che non sta impostando correttamente il tipo di contenuto. – stef

+0

Ora ho aggiunto intestazioni CURL – sandelius

+0

Questo potrebbe essere specifico per il browser. Su quale browser stai testando? – bdares

risposta

10

ho capito.

Sono stati i turbolinks a rovinare tutto. Ho aggiunto data-no-turbolink al link di esportazione e ora funziona come previsto.

+0

+1: aggiungendo che alla mia lista di turbolinks ho trovato anche il problema – bdares

+1

, ma senza turbolinks. Avevo il telecomando: true set nel mio link_to. Rimozione del telecomando: true risolto il problema. – cgat

2

send_data ha un hash opzione, quindi il tipo, la disposizione e il nome del file deve essere impostato in un hash:

def export 
    send_data(current_user.contacts.to_csv, 
    type: 'text/csv', disposition: 'attachment', filename: 'contacts.csv') 
end 
+0

Sto passando un hash come secondo argomento. Ho provato anche tu la tua strada, ma rende solo il contenuto sullo schermo. – sandelius