# Disabling layout in action disables rendering of action data

**URL:** <https://www.ruby-forum.com/t/disabling-layout-in-action-disables-rendering-of-action-data/165445>\
**Category:** Rails\
**Created:** [April 14, 2009, 12:59am UTC](https://www.ruby-forum.com/t/disabling-layout-in-action-disables-rendering-of-action-data/165445 "2009-04-14T00:59:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sktib](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@sktib](https://www.ruby-forum.com/u/sktib)\
**Post date:** [April 14, 2009, 12:59am UTC](https://www.ruby-forum.com/t/disabling-layout-in-action-disables-rendering-of-action-data/165445/1 "2009-04-14T00:59:21Z")

</div>

Folks,

I have a base layout (views/layouts/base.erb) included from  
ApplicationController – layout ‘base’

This seems to work fine and all controllers automatically include that  
layout. However I am now trying to disable layout for certain actions  
when I do a GET on them. For example I try to GET some json data using  
[http://localhost:3001/admin/someaction/1.json](http://localhost:3001/admin/someaction/1.json) (from within my view page  
to load some json data dynamically)

The “someaction” action in admin controller is something like below

def someaction  
respond\_to do |format|  
format.html {  
}  
format.json {  
render(:layout =\> false) \<— Doing this disables sending of  
@somevar through the view  
@somevar = compute\_contents\_of\_this\_var\_in\_json  
}  
logger.info("@somevar = " + @somevar)  
end  
end

In views/admin/someaction.json.erb I have a single line as below  
\<%= @somevar %\>

This basically sends out the json data in @somevar to the browser.

The problem I am running into is that when I set rendering of layout to  
false in someaction, no data gets sent out (@somevar has the needed data

- I see that in the logs) and when I don’t turn off rendering of layout,  
I get all the HTML from my layout (as I would expect) that I don’t want.

I tried removing the layout statement from ApplicationController and  
then without having to turn off layout rendering in someaction, it sends  
out the right json data without the HTML.

I don’t understand why turning off rendering of layout in someaction  
disables sending of the json data in the @somevar variable. Sounds like  
I am missing something basic but not sure what it is. I am on 2.2.2

Thanks for your help.  
-S
