Sunday, November 22, 2009

So you can actually nest rails layout in nth level...

Yeah I know probably I have overlooked this feature (I mean, I should have know this long ago :P), but this is something really handy:

http://guides.rubyonrails.org/layouts_and_rendering.html#using-nested-layouts

There are a few things you can learn here:
1. A yield can be conditional by nil- if you yield something first or yield the other one, that would give you a chance to select which to be yielded with the first one as priority.
2. So by capturing everything in the layout and then call a render function, you can nest the layout.
3. Seems this also give me the answer to find out if a content_for is defined or no, by simply checking the yield function result nil would let me know if its defined, and I think as long as its not <%= that wouldn't trigger an output as well. Sweet.

0 comments: