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
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?
@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
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 (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.
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
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