views:

36

answers:

2

Ok so I have a small project with two different scaffoldings I've made.In the layouts directory therefor there is two different layout.html.erb files.

My question is how to condense this into just one main layout file that the two scaffolded views share.

Basically my purpose for doing this is so that I only have to have my navigation bar and header and other such things all in one place.

+3  A: 

if you name the layout file application.html.erb, then it will be the default layout file. If you specify a layout file by the same name of your controller, that will override the default layout.

From Rails Guides:

To find the current layout, Rails first looks for a file in app/views/layouts with the same base name as the controller. For example, rendering actions from the PhotosController class will use app/views/layouts/photos.html.erb (or app/views/layouts/photos.builder). If there is no such controller-specific layout, Rails will use app/views/layouts/application.html.erb or app/views/layouts/application.builder. If there is no .erb layout, Rails will use a .builder layout if one exists. Rails also provides several ways to more precisely assign specific layouts to individual controllers and actions.

source: http://guides.rails.info/layouts_and_rendering.html

EDIT:

I should add that you can specify any layout to be your default in the Application Controller:

class ApplicationController < ActionController::Base
  layout 'some_layout_name'
end

And that will override name matching that rails does automatically.

I hope this helps!

Geoff Lanotte
Thanks! of course with rails it's all about convention lol
Earlz
A: 

You can have an application.html.erb in your layouts directory that will be shared by all of the views

mportiz08