render :text should have mime type text/plain #3234

Closed
pwim opened this Issue Oct 6, 2011 · 6 comments

Comments

Projects
None yet
5 participants
Contributor

pwim commented Oct 6, 2011

render :text => "string" is used to send plain text – with no markup at all – back to the browser by using the :text option to render. As such, the mime type should be text/plain. Is there any reason why it isn't?

Member

sikachu commented Oct 6, 2011

Nope. Please fix it if it's an issue and send us a pull request.

Contributor

andriytyurnikov commented Oct 11, 2011

Well, you both assuming cases where no layout is used, rendering text into HTML layout works fine with current implementation

Contributor

dcrec1 commented Oct 11, 2011

Hey, I've created a pull request that fixes this:

#3299

Contributor

andriytyurnikov commented Oct 11, 2011

Well, this one is yours ;)
But chances are - it will be rejected -

render :text => "Hello", :content_type => Mime::TEXT

will work just fine, and those tests you've changed - ensure current usage

Owner

jeremy commented Oct 12, 2011

:text doesn't mean text/plain in particular. It just means "render this string directly, no templates or anything."

You can just as well return HTML within that string. I think the default is a good choice here, and, as @andriytyurnikov suggested, you can be explicit about sending plain text in other cases.

jeremy closed this Oct 12, 2011

Contributor

dcrec1 commented Oct 12, 2011

I think the confusion began because the documentation says you can use :text to send plain text back to the client and if Rails is sending plain text then it should set the content type header as text/plain .

I agree that today things are not like this but I think that maybe there should be two options:

render :text => ...
render :html => ...

where the difference would be the header.

@iloveitaly iloveitaly added a commit to iloveitaly/cangaroo that referenced this issue Mar 17, 2016

@iloveitaly iloveitaly Using text/html in spec instead of text/plain
text/plain throws an unknown content type error rails/rails#3234
569bd39

@iloveitaly iloveitaly added a commit to iloveitaly/cangaroo that referenced this issue Mar 17, 2016

@iloveitaly iloveitaly Using text/html in spec instead of text/plain
text/plain throws an unknown content type error rails/rails#3234
316556c

@iloveitaly iloveitaly added a commit to iloveitaly/cangaroo that referenced this issue Mar 31, 2016

@iloveitaly iloveitaly Using text/html in spec instead of text/plain
text/plain throws an unknown content type error rails/rails#3234
0949f91

@iloveitaly iloveitaly added a commit to iloveitaly/cangaroo that referenced this issue Mar 31, 2016

@iloveitaly iloveitaly Using text/html in spec instead of text/plain
text/plain throws an unknown content type error rails/rails#3234
38e4c8c

@iloveitaly iloveitaly added a commit to iloveitaly/cangaroo that referenced this issue Apr 4, 2016

@iloveitaly iloveitaly Using text/html in spec instead of text/plain
text/plain throws an unknown content type error rails/rails#3234
11eb2db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment