How to generate a layout for a controller

Create the layout under app/views/layouts and depending on your version of rails:

1.x - mycontroller.rhtml 2.x - mycontroller.html.erb

Franz Strebel wrote:

Hi…,

It will take automatically.

app/view/layout/

Here layout folder is meant for layouts

For any controller you can use layout by naming layout file as same name as controller…

Regards hafeez

Or you can set layout directly in your controller:

class MyController < ApplicationController   layout 'some_other_layout' end

Regards, Bosko

If I create this layout file manually, how will rails link it to the views? Which URL refer to this layout?

You can specify which layout to use in your controller.

layout 'main'

That would use app/views/layouts/main.html.erb as the layout. You can specify a default global layout by placing this in the application controller.

I set this in my controller and which link I should use for this layout. When I invoke the controller in the browser, it will refer to the index page not the layout page.

Give this a read - it explains layouts and how to use them better than I can here.

John Yerhot wrote:

I set this in my controller and which link I should use for this layout. When I invoke the controller in the browser, it will refer to the index page not the layout page.

Give this a read - it explains layouts and how to use them better than I can here.

Ruby on Rails - Layouts

Oh, rails handles the automatic linking with the layout and views.

thanks.