yamaoka
yamaoka

Reputation: 131

Why is an html.erb file called after a controller is called?

I don't quite understand the flow of an MVC. A request of a page goes to a route and that route calls an action in a controller. But then why is a view called after that? I don't really understand which code calls the view and displays it to the user.

root 'controllername#index'

def index
end

Upvotes: 1

Views: 151

Answers (1)

Shannon
Shannon

Reputation: 3018

A controller action will search for a view with the same name e.g. controller action index will search for views such as index.html.erb and index.html.haml in their associated directory. To have a controller action without a view, something like render :nothing => true can be used.

More information can be found in the Action View guide.

Upvotes: 3

Related Questions