A layout defines all the surroundings of an HTML page. It is the latter which will then define the location of an object relative to the other and relative to the size of the window. If you are a beginner or an amateur and want to be part of a ruby on rails development company, you need to know the moin Rendering and Layout.
To create a layout you will have to go in the / app / views / layouts / to create a new file: the notes.html.erb. In the latter, you will then write code that will return to each of your pages. The content of the page will then be inserted by Rails from yield that is in the template. It will also ensure that it remains only in the section #content files. If you then go to your website, you get the same result only you will no longer need to write redundant code.
Content_for is used to divide the layout into blocks. This method then allows you to insert content anywhere in your layout with the yield. To set an example in our blocks /app/views/layouts/notes.html.erb layout, you have to yield: nom_du_bloc. It'll then, to change the content of your pages to reflect this block.
How Rails defined layout?
With Rails, it's quite simple. Indeed, when rendering called by the controller, Rails will automatically look in the / app / views / layouts / if a layout corresponds to the controller. In this case, it will then use it. Otherwise, it will use the default application layout. It is even possible when you set yourself the layout to be called. To do this, either you use a key word in the controller layout or you specify the layout option in render.