defining layouts and application.rhtml

Because a layout that corresponds to your controller name allows you to override the default application layout. Or conversely, any controller without a layout defined automatically inherits the application layout. You are not required to create a layout for each controller. Heck you don't even have to create a view template. You can render directly to the response that is sent to the user agent. For example, render :text => 'Hello World!' in an action will spit out Hello World!.

You don’t have to do that. Just don’t create layouts for your controllers. Just view templates for your actions. The view templates will automatically use the application layout.

define app/views/layouts/application.rhtml define app/views/<my_share_folder>/_<shared_partial>.rhtml define app/views//.rhtml

within app/views//.rhtml file render the shared partial like so

render(:partial => ‘<my_share_folder>/<shared_partial>’, …)

Your action will get the appropriate view, embed the shared partial, and use the application layout to wrap the templates. If you include a path to the partial, app/views is considered the root, otherwise Rails looks in app/views/.

I suggest reading Agile Web Development with Rails. This is specifically covered in the book.

I was struggling a bit with layouts as well. I new about partials , but then I read up on the @content_for . That is pretty powerful. In one layout I can have multiple partials whereever I want. Check the api (sorry don't have the link) As an example though - In my view I have this , with the html and code between - <% content_for 'postform' do -%> <% end-%>

then in my layout i just decide where that goes and put the @content_for_postform

Hope this helps and is relevant.

Stuart

According to the documentation, your call to @content_for_postform is deprecated. It says that the preferred way now is to use <%= yield :postform %>.

-- James