Forum: Ruby on Rails Getting content-disposition in the HTTP response headers.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E6496b2d722d443e3752eb51c962e8da?d=identicon&s=25 hartog (Guest)
on 2007-02-28 15:33
(Received via mailing list)
Hi,

I am quite new to Ruby and Rails, although I have cracked most of my
puzzles by googling and trying I just can't get this one to get going
for me.

Here is my problem:

I am trying to cough up a nice text/csv file from my browser and would
like to set this:

  Content-type: text/csv
  Content-disposition: attachment; filename="the_file.csv"

in my HTTP response header, but so far I haven't found any ''tricks''
to achieve the 'Content-disposition' part.

Any help would be dearly appreciated.


Kind regards,
Hartog.
43c0415c9e2d26c0ecbdbf8aa8e3671f?d=identicon&s=25 S2 (Guest)
on 2007-02-28 15:37
(Received via mailing list)
in

class ApplicationController < ActionController::Base
  before_filter :set_headers

  private
    def set_headers
      @headers["Content-Type"] = "text/csv"
      @headers["Content-disposition"] = 'attachment;
filename="the_file.csv"'
    end
end

very easy :)
E6496b2d722d443e3752eb51c962e8da?d=identicon&s=25 Hartog C. de Mik (Guest)
on 2007-02-28 16:01
(Received via mailing list)
On Wed, Feb 28, 2007 at 06:36:34AM -0800, S2 wrote:
> > like to set this:
>
> class ApplicationController < ActionController::Base
>   before_filter :set_headers
>
>   private
>     def set_headers
>       @headers["Content-Type"] = "text/csv"
>       @headers["Content-disposition"] = 'attachment;
> filename="the_file.csv"'
>     end
> end

Thank you!

> very easy :)

Once you how, yes indeed.  :->



I do however think that render() (from: ApplicationController::Base)
should allow for a ':disposition' option as well.

Where should I go for such a feature request?



Grtz,
Hartog
8c66dc72416bd3537bf00cc297b0b226?d=identicon&s=25 Zeff (Guest)
on 2007-02-28 16:17
(Received via mailing list)
I have a problem that may be resolved with this, if I understand it
correctly.  I have one controller/view that keeps rendering as text/
plain ... that's how the headers come back from the server.  My
content type is set correctly in the header in my layout file.

Can I do something similar in my specific controller to force it to
render as text/html instead of text/plain?

Thanks

Zeff
24d2f8804e6bb4b7ea6bd11e0a586470?d=identicon&s=25 Jeremy Kemper (Guest)
on 2007-03-01 03:54
(Received via mailing list)
On 2/28/07, Hartog C. de Mik <hartog@2organize.com> wrote:
>
> > very easy :)
>
> Once you how, yes indeed.  :->
>
> I do however think that render() (from: ApplicationController::Base)
> should allow for a ':disposition' option as well.


send_data the_csv_data, :filename => 'data.csv', :type => 'text/csv'

http://api.rubyonrails.org/classes/ActionControlle...

Where should I go for such a feature request?


Submit requests, bugs, and patches at http://dev.rubyonrails.org/

jeremy
Aafa8848c4b764f080b1b31a51eab73d?d=identicon&s=25 Phlip (Guest)
on 2007-03-01 04:13
(Received via mailing list)
hartog wrote:

>  Content-type: text/csv
>  Content-disposition: attachment; filename="the_file.csv"

http://www.rubyinside.com/railstips/tag/send_file

--
  Phlip
  http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
This topic is locked and can not be replied to.