Views and Rendering
Returning responses.
What Is a View?
A view is a template that produces the response sent to the client, usually HTML. It turns the data a controller prepared into a page.
- Views live in
app/views. - They are grouped by controller, like
app/views/articles. - The default template name matches the action.
Convention-Based Rendering
By default an action renders the template named after it. The index action of ArticlesController renders app/views/articles/index.html.erb with no explicit render call.
def index
@articles = Article.all
# automatically renders articles/index.html.erb
endAll lessons in this course
- Routes and Resources
- Controllers and Actions
- Strong Parameters
- Views and Rendering