# @content\_for\_layout or changing default fields on "new" page

**URL:** <https://www.ruby-forum.com/t/content-for-layout-or-changing-default-fields-on-new-page/113539>\
**Category:** Rails\
**Created:** [September 1, 2007, 11:20am UTC](https://www.ruby-forum.com/t/content-for-layout-or-changing-default-fields-on-new-page/113539 "2007-09-01T11:20:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Artur\_Kaminski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47774/32.png) [@Artur\_Kaminski](https://www.ruby-forum.com/u/Artur_Kaminski)\
**Post date:** [September 1, 2007, 11:20am UTC](https://www.ruby-forum.com/t/content-for-layout-or-changing-default-fields-on-new-page/113539/1 "2007-09-01T11:20:33Z")

</div>

Hi all,

I test my small Rails apps using SQLite3, but I think the problem  
appeares in every type of database.  
.  
When I create table and scaffolding apps, a HTML view is based on  
columns types. Everything is OK until I want to change preconfigured  
behaviour.  
.  
I created table with a column of type INTEGER, but I wanted to display  
check box instead of text field and then save 0 or 1 in database. If I  
created table with column BINARY, Rails would show me check box  
instead of text field, but it is not the case (I have no BINARY data  
type, and I do not know Rails has such possibility).  
.  
I tried to investigate how Rails automagically displays final web  
page, and I find @content\_for\_layout. I think it is the variable  
containing the data types the user wants to type in on “new” page. Is  
it correct? Where can I find its definition and overwrite it? I agree  
to write a lot of code 🙂  
.  
I tried to read “Agile Rails…”, but authors missed some explanations  
and in the book sometimes has listings I can only type in and observe  
the effects, without understanding what happend behind the scene.  
Could you recommend a FAQ/manual/how-to?

Regards,  
Artur

---

<div class="post-metadata">

**Author:** ![Artur\_Kaminski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47774/32.png) [@Artur\_Kaminski](https://www.ruby-forum.com/u/Artur_Kaminski)\
**Post date:** [September 1, 2007, 7:54pm UTC](https://www.ruby-forum.com/t/content-for-layout-or-changing-default-fields-on-new-page/113539/2 "2007-09-01T19:54:37Z")

</div>

@content\_for\_layout is an instance variable that rails creates to hold  
the rendered html so that it can be inserted into a layout. Its use  
has been deprecated in favor of simply using yield.

If you are using scaffold :model in your controller then rails  
magically creates code that you never see, so it can be a little  
confusing to try to understand what is going on. You can use ruby  
script/generate scaffold Model to generate the code and the files so  
you can see what rails is doing behind the scenes and modify it to fit  
your needs.

I would like to stress that you are not in any way bound to using the  
scaffolding, generated or not, to create your rails application.  
Indeed the old non-restful scaffolding is little more than a proof-of-  
concept and isn’t really production quality code. Luckily the whole  
point of rails is to write your views, controllers, and models in  
whatever way you need, and rails is designed to let you do just that.

So generate that scaffold code (if you haven’t yet), dig around the  
files it creates to see what rails does, and then get busy rewriting  
it to suit your needs. Most experienced rails developers I know don’t  
even bother with the scaffolding in the first place.

I would also recommend reading through the relevant sections of  
[api.rubyonrails.com](http://api.rubyonrails.com) (such as check\_box), and reading through \_why’s  
poignant guide or the ruby pickaxe to get a better understanding of  
the Ruby language as well.

Rein

---

<div class="post-metadata">

**Author:** ![Artur\_Kaminski](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e47774/32.png) [@Artur\_Kaminski](https://www.ruby-forum.com/u/Artur_Kaminski)\
**Post date:** [September 2, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/content-for-layout-or-changing-default-fields-on-new-page/113539/3 "2007-09-02T13:58:55Z")

</div>

On Sep 1, 6:53 pm, removed\_email\_address@domain.invalid wrote:

> even bother with the scaffolding in the first place.
> 
> I would also recommend reading through the relevant sections of  
> [api.rubyonrails.com](http://api.rubyonrails.com) (such as check\_box), and reading through \_why’s  
> poignant guide or the ruby pickaxe to get a better understanding of  
> the Ruby language as well.

Rein,

thanks a lot for the explanation. While reading your post I realised,  
that I actually tried to investigate what and why scaffolding do  
instead of work on ActiveRecord. I thought it would be simplest way to  
learn Rails if I found all dependencies in the code generated by  
scaffolding mechanism. It was to hard 🙂 Usually analysing an example  
is the best method of learning for me, but there are too many hidden  
things.  
.  
It was the first thing to ./script/generate scaffold MyModel, as an  
easiest way for newbies, but “digging” the final code has driven me to  
this news group. Its time for [api.rubyonrails.com](http://api.rubyonrails.com) 🙂

Regards  
Artur
