In which folder should I put the "global" shared partial patterns?

I am using Ruby on Rails 3.0.7, and I plan to use partial templates. All classes in my application will use the same partial parts, so I have to decide where to place them.

Can global global partial patterns be placed in the lib folder? If not, then what is the usual practice for choosing a folder, where can I place them? Any tips on the proper name and loading of this folder?

+42
ruby ruby-on-rails ruby-on-rails-3 templates dry
Jul 01 2018-11-11T00:
source share
3 answers

The standard places all shared parts in app/views/shared and refers to them as

 render :partial => 'shared/partial_name' 

If you have a standard “line in the list” partial (say, for an index page), you can use a common partial, for example:

 # To render a single object row: render :partial => 'shared/item', :locals => { :item => @item } # Or to render them all: render :partial => 'shared/item', :collection => @items 
+53
Jul 01 '11 at 15:52
source share

Rails 4:

enter the partial files that you intend to use through your application in /app/views/application

Then anywhere in the application you can easily:

 render partial: 'partial_name', variable_name: variable 

An added benefit is that you can always override the partial in a particular viewing space by overriding what that partial means in /app/views/controller_name/_partial_name.html.erb , and calls to the partial link will refer to a more specific context in which You are at. No, you get a partial application level.

Proposal taken from Thoughtbot

+15
Sep 18 '14 at 16:17
source share

Conventions should put them under app/views/shared

If you have many particles, I would recommend you put them in subdirectories of this folder, regardless of what makes sense for your application, since having a large number of partial files in one directory is usually not a good practice.

+4
Jul 01 2018-11-11T00:
source share



All Articles