Class: CSV
Overview
Comma Separated Values extensions
Class Method Summary collapse
-
.http_headers(options = {}) ⇒ Hash<String,String>
Options - filename: defaults to “data.csv” - request: the incoming http request, which is used to return MSIE-specific headers.
-
.http_headers_adjust_for_broken_msie(options = {}) ⇒ Hash<String,String>
Helper to try to “do the right thing” for the common case of Rails & MS IE.
Class Method Details
.http_headers(options = {}) ⇒ Hash<String,String>
Options
- filename: defaults to "data.csv"
- request: the incoming http request, which is used to return MSIE-specific headers
Ideas from stackoverflow.com/questions/94502/in-rails-how-to-return-records-as-a-csv-file/94520
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sixarm_ruby_ramp/csv.rb', line 21 def self.http_headers(={}) filename = [:filename] || 'data.csv' =self.http_headers_adjust_for_broken_msie() content_type = [:content_type] || 'text/csv' return [:cache] \ ? { 'Content-Type' => content_type, 'Content-Disposition' => "attachment; filename=\"#{filename}\"", } \ : { 'Content-Type' => content_type, 'Cache-Control' => 'no-cache, must-revalidate, post-check=0, pre-check=0', 'Expires' => "0", 'Pragma' => 'no-cache', 'Content-Disposition' => "attachment; filename=\"#{filename}\"", } end |
.http_headers_adjust_for_broken_msie(options = {}) ⇒ Hash<String,String>
Helper to try to “do the right thing” for the common case of Rails & MS IE.
Rails automatically defines a request object, that has an env HTTP_USER_AGENT.
47 48 49 50 51 52 53 54 55 |
# File 'lib/sixarm_ruby_ramp/csv.rb', line 47 def self.http_headers_adjust_for_broken_msie(={}) request = [:request] || request msie = (request and request.env['HTTP_USER_AGENT'] =~ /msie/i) if msie [:content_type]||='text/plain' [:cache]||=false end return end |