Hi: I have one application and four controllers. 3 controllers need identical code in their layouts. The fourth is a superset of the other 3. To be more specific, there is 10 lines of code buried between the <head> & </head> tags that only is required for the fourth controller. What is the most efficient way to get this done? I know that if they all required the same code, that I could just put that code in a file called application.rhtml at the root layout level, but that is not quite the case here. Thanks in advance for any suggestions. bruce PS. Would anyone also like to recommend to me an excellent book on object oriented programming? If it could be based on ruby that would be ideal but not necessary.
On 12/8/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote:> Hi: > > I have one application and four controllers. 3 controllers need > identical code in their layouts. The fourth is a superset of the > other 3. To be more specific, there is 10 lines of code buried > between the <head> & </head> tags that only is required for the > fourth controller. > > What is the most efficient way to get this done? I know that if they > all required the same code, that I could just put that code in a > file called application.rhtml at the root layout level, but that is > not quite the case here. > > Thanks in advance for any suggestions. > > bruce > > PS. Would anyone also like to recommend to me an excellent book on > object oriented programming? If it could be based on ruby that would > be ideal but not necessary.Use one layout for all 4 controllers and put this into the head section: <head> ... ... <%= @content_for_head %> </head> Then in the odd controller views that need extra content: <% content_for ''head'' do -%> ... ... <% end -%> -- rick http://techno-weenie.net
Rick: Thanks so much. Very cool new feature I did not know about (new to me). Much appreciated, as is the speed of your reply. bruce On 8-Dec-05, at 9:36 AM, Rick Olson wrote:> On 12/8/05, Bruce Balmer <brucebalmer-ee4meeAH724@public.gmane.org> wrote: >> Hi: >> >> I have one application and four controllers. 3 controllers need >> identical code in their layouts. The fourth is a superset of the >> other 3. To be more specific, there is 10 lines of code buried >> between the <head> & </head> tags that only is required for the >> fourth controller. >> >> What is the most efficient way to get this done? I know that if they >> all required the same code, that I could just put that code in a >> file called application.rhtml at the root layout level, but that is >> not quite the case here. >> >> Thanks in advance for any suggestions. >> >> bruce >> >> PS. Would anyone also like to recommend to me an excellent book on >> object oriented programming? If it could be based on ruby that would >> be ideal but not necessary. > > Use one layout for all 4 controllers and put this into the head > section: > > <head> > ... > ... > <%= @content_for_head %> > </head> > > Then in the odd controller views that need extra content: > > <% content_for ''head'' do -%> > ... > ... > <% end -%> > > > -- > rick > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Rick Olson <technoweenie@...> writes:> > Use one layout for all 4 controllers and put this into the head section: > > <head> > ... > ... > <%= <at> content_for_head %> > </head> > > Then in the odd controller views that need extra content: > > <% content_for ''head'' do -%> > ... > ... > <% end -%> > > -- > rick > http://techno-weenie.net >I have two layout-related questions I''d like to piggy-back on this one. First, what other @content_for_... helpers may be lurking out there and where can I look to find them all. Second, can layouts be nested? I know you can have named layouts, then rails next looks for one matching the name of your controller, then finally for application.rhtml. What I''d like to know is this. Say for example I define the outer border of my page in my application.rhtml and have my @content_for_body inside of a table. Can I then create controller layout files that would define the upper nav section as a table row to be included in the outer application layout, then have the bulk of my table built by a named layout replacing the @content_for_body in my controller layout? Hopefully I''ve explained this well, but my question really is can you nest layouts based on the default rails search path?