# Render :nothing deprecated?

**URL:** <https://www.ruby-forum.com/t/render-nothing-deprecated/117596>\
**Category:** Rails\
**Created:** [October 18, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/render-nothing-deprecated/117596 "2007-10-18T12:27:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fjan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@fjan](https://www.ruby-forum.com/u/fjan)\
**Post date:** [October 18, 2007, 12:27pm UTC](https://www.ruby-forum.com/t/render-nothing-deprecated/117596/1 "2007-10-18T12:27:38Z")

</div>

I get a warning “render :nothing deprecated, use render :file  
instead”… but I cannot find any info on how to use render :file to  
render nothing. It’s also not mentioned on the deprecated items web  
page, it this warning a bug?

---

<div class="post-metadata">

**Author:** ![fjan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@fjan](https://www.ruby-forum.com/u/fjan)\
**Post date:** [October 18, 2007, 2:14pm UTC](https://www.ruby-forum.com/t/render-nothing-deprecated/117596/2 "2007-10-18T14:14:20Z")

</div>

On 18 Oct 2007, at 11:27, Fjan wrote:

> I get a warning “render :nothing deprecated, use render :file  
> instead”… but I cannot find any info on how to use render :file to  
> render nothing. It’s also not mentioned on the deprecated items web  
> page, it this warning a bug?

render :nothing =\> true should still work and not be deprecated.

Ferd

---

<div class="post-metadata">

**Author:** ![fjan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@fjan](https://www.ruby-forum.com/u/fjan)\
**Post date:** [October 18, 2007, 3:52pm UTC](https://www.ruby-forum.com/t/render-nothing-deprecated/117596/3 "2007-10-18T15:52:07Z")

</div>

On 10/18/07, Fjan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I get a warning “render :nothing deprecated, use render :file  
> instead”… but I cannot find any info on how to use render :file to  
> render nothing. It’s also not mentioned on the deprecated items web  
> page, it this warning a bug?

To add to what Fred said, you may be wondering why you need

:nothing =\> true

instead of just

:nothing

The reason is that you used to be able to write:

render “path/to/some\_file.rhtml”

which was equivalent to

render\_file “path/to/some\_file.rhtml”

The Rails guys decided to get rid of all the render\_xxx methods and  
just have a single render method that takes a hash of options:

render :action =\> ‘blah’  
render :file =\> ‘blech’  
render :inline =\> ‘\<%= foo %\>’

In order to provide backward compatibility, render looks at its  
argument. If it’s a Hash, it’s treated as the new-style way of doing  
things. Otherwise, it’s assume to be the old render “some\_file”  
method, so the argument gets passed along to render\_file, and a  
deprecation warning is issued (since this will go away completely in  
Rails 2.0).

So, with all that background,

render :nothing

actually is transformed into

render :file =\> :nothing

which isn’t what you intended.

By writing

render :nothing =\> true

render receives a Hash as it’s argument (because of the =\> operator),  
so you get nothing rendered.

Ruby has an interesting feature in method calls, where a Hash literal  
and the _end_ of a parameter list does not need to be enclosed in  
braces. So

render :nothing =\> true

is really the same as

render({:nothing =\> true})

It’s a nice feature, because it cuts down on the “line noise” so  
common with Perl e.g., but you need to be aware of it because it can  
be misleading. For example:

update\_attribute :foo, “Bar” # two arguments passed  
update\_attributes :foo =\> “Bar” # _one_ argument (a Hash)  
passed

---

<div class="post-metadata">

**Author:** ![fjan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/6de8d8/32.png) [@fjan](https://www.ruby-forum.com/u/fjan)\
**Post date:** [October 18, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/render-nothing-deprecated/117596/4 "2007-10-18T16:07:19Z")

</div>

Ah, thanks for the reply both. I noticed it’s my own fault (as usual),  
I used a string instead of a symbol but the warning message threw me  
off:

DEPRECATION WARNING: You called render(‘nothing’), which is a  
deprecated API call. Instead you use render :file =\> nothing.
