Andrew Grimm
Andrew Grimm

Reputation: 81500

What's the layouts folder for in Rails?

I understand that .html.erb files go within app/views or its subfolders. But what is the app/views/layouts folder in particular for in Rails?

Upvotes: 2

Views: 2156

Answers (2)

shashi verma
shashi verma

Reputation: 973

Layout in rails framework is very important folder, main layout of your application is define here as application.html.erb and all the views are yielded here using <% yield %>

Upvotes: 0

Prakash Murthy
Prakash Murthy

Reputation: 13067

app/views/layouts is the folder in which rails looks for the layouts.

From http://guides.rubyonrails.org/layouts_and_rendering.html#finding-layouts :

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.

What is a layout?

A layout defines the surroundings of an HTML page. It's the place to define common look and feel of the page.

The RailsCasts episode - All About Layouts - though very old, is still very useful in this context.

Upvotes: 6

Related Questions