Artur Kaminski
2007-Sep-01 09:19 UTC
@content_for_layout or changing default fields on "new" page
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Sep-01 17:53 UTC
Re: @content_for_layout or changing default fields on "new" page
@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 (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 On Sep 1, 4:19 am, Artur Kaminski <my.home.my.cas...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Artur Kaminski
2007-Sep-02 11:58 UTC
Re: @content_for_layout or changing default fields on "new" page
On Sep 1, 6:53 pm, rein.henri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> @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 (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 :-) Regards Artur --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---