In which folder should I put "global" shared partial templates? [duplicate] In which folder should I put "global" shared partial templates? [duplicate] ruby ruby

In which folder should I put "global" shared partial templates? [duplicate]


The standard is placing all shared partials in app/views/shared, and referencing them as

render :partial => 'shared/partial_name'

If you have a standard "row in a list" partial (say, for an index page), you could use a shared partial like:

# To render a single object row:render :partial => 'shared/item', :locals => { :item => @item }# Or to render them all:render :partial => 'shared/item', :collection => @items


Rails 4:

put the partials you intend to use through out your application in /app/views/application

Then anywhere in your application you can easily:

render partial: 'partial_name', variable_name: variable

The added benefit is that you can always override the partial in a particular view space by redefining what that partial means in /app/views/controller_name/_partial_name.html.erb and the calls to the partial will then reference the more specific context you're in. If that doesn't exist you get the application level partial.

Suggestion taken from Thoughtbot


Conventions is to put them under app/views/shared

If you're going to have many partials, I'd recommend you putting them into subdirectories of that folder, whatever makes sense to your application, since having many partials in one directory is generally not a good practice.