Ruby on Rails Views Structure


Example

As Rails follows the MVC pattern Views are where your "templates" are for your actions.

Let's say you have a controller articles_controller.rb. For this controller you would have a folder in views called app/views/articles:

app
|-- controllers
|   '-- articles_controller.rb
|
'-- views
    '-- articles
    |   |- index.html.erb
    |   |- edit.html.erb
    |   |- show.html.erb
    |   |- new.html.erb
    |   '- _partial_view.html.erb
    |
    '-- [...]

This structure allows you to have a folder for each controller. When calling an action in your controller the appropriate view will be rendered automatically.

// articles_controller.rb
class ArticlesController < ActionController::Base
  def show
  end
end

// show.html.erb
<h1>My show view</h1>