---
title: Directory for shared partials in Rails
teaser:
tags: web,rails
author: Dan Croak
published_on: 2009-08-31
---

Which directory should contain shared partials in a Rails app?

## Rejected option: `app/views/layouts` directory

I've seen this:

    app/views/layouts/application.html.erb
    app/views/layouts/_flashes.html.erb
    app/views/layouts/_footer.html.erb
    app/views/layouts/_header.html.erb
    app/views/layouts/_javascript.html.erb
    app/views/layouts/_navigation.html.erb

However, the layout directory should contain... layouts.

    app/views/layouts/application.html.erb

## Rejected option: `app/views/shared` directory

I've seen this:

    app/views/shared/_flashes.html.erb
    app/views/shared/_footer.html.erb
    app/views/shared/_header.html.erb
    app/views/shared/_javascript.html.erb
    app/views/shared/_navigation.html.erb

That was the recommendation in the classic, [Agile Web Development with
Rails](http://www.pragprog.com/titles/rails2/agile-web-development-with-rails).

Also, when you extracted a partial from a layout in
[rails.vim](http://rails.vim.tpope.net) using `:Rextract`, it would
automatically place the extracted partial into the shared directory.

## Current solution: `app/views/application` directory

This is our current standard:

    app/views/application/_flashes.html.erb
    app/views/application/_footer.html.erb
    app/views/application/_header.html.erb
    app/views/application/_javascript.html.erb
    app/views/application/_navigation.html.erb

The main reason is a subtle, but functional difference: [template
inheritance](http://asciicasts.com/episodes/269-template-inheritance).

Also, invoking the partials is slightly shorter with this approach. Instead of:

    render 'shared/navigation'

This is possible from every view:

    render 'navigation'

We have formalized this convention in
[Suspenders](https://github.com/thoughtbot/suspenders/blob/master/lib/suspenders/app_builder.rb#L49-L59)

Sharing is caring.

![Care bears](https://thoughtbot-training.s3.amazonaws.com/images/care_bears.jpg)
