Layouts in Ruby on Rails are surrounding webpages (HTML pages). Views can be shown combined with layouts.
Layout files are stored in
app/views/layouts/. You can use a layout many times in views.
This makes your app maintainable, instead of having to change 100s of views to change the look of the app, change one layout file.
A layout file is a web page, a HTML template. All of these are stored in
app/views/layouts, navigate there.
Add a file named
standard.html.erb. Add this contents to the template:
The next step is to map the route to the view combined with the layout. You made a weather app with route
/weather/ in the previous article. If you haven’t made the app from previous article, make it.
In the controller, tell Rails to use this layout.
app/controllers/weather_controller.rb. Change it into:
class WeatherController < ApplicationController
Start Rails server with
rails server. This will start the Rails web server on the machine.
Congratulations! If you now open /weather/ you’ll see the layout has been added to your view.