# How to Explicitly Render a Different View in Rails

*Published on January 19, 2023*

---


A standard Rails controller receives an incoming HTTP request, generates the data needed for the response, and renders an HTML view template.

> 💡 An API controller returns JSON or XML response data, but that's a topic for a separate blog post.

By convention, the Rails view templates are stored under the&nbsp;`app/views`&nbsp;directory, in the folders named after the controllers. The name of the folder is the snake\_cased version of the controller name, after stripping the string&nbsp;`Controller`&nbsp;from it. There's a view file named after each action.

For example, the views for the&nbsp;`PostsController`&nbsp;controller are stored under the&nbsp;`app/views/posts`&nbsp;directory. If this controller has two actions named&nbsp;`show`&nbsp;and&nbsp;`index`, there will be two view templates:

1. `app/views/posts/show.html.erb`
2. `app/views/posts/index.html.erb`

Rails automatically figures out which view template to render based on the action name. That is, if you do not explicitly render something at the end of a controller action, Rails will automatically look for the&nbsp;`action_name.html.erb`&nbsp;template in the controller's view directory and render it.

In those rare cases where you want to render a different view, you can use the&nbsp;`render`&nbsp;helper method as follows:

```ruby
class PostsController < ApplicationController
  def index
    @posts = Post.all
    
    render "articles/index"
  end
end
```

In this example, Rails will render the&nbsp;`app/views/articles/index.html.erb`&nbsp;view template, instead of the&nbsp;`app/views/posts/index.html.erb`&nbsp;template.

💡 **Did you know?**&nbsp;You can customize the behavior of&nbsp;`render`&nbsp;in various ways. You can render the default view for a Rails template, or a specific template (like we just did), or a file, or inline code, or nothing at all. You can also render text, JSON, or XML. Finally, you can specify the content type or HTTP status of the rendered response as well. We'll learn about them all in future posts in this series, so stay tuned.

