'Ruby on Rails. Organizing common partials in subfolders
I'm Rails beginner.
As i know, i should place my common partials in app/views/application like app/views/application/_validation_errors.html.erb. In that case i can use render 'validation_errors' everywhere in my views and Rails will find right partial.
But i want to organize my particles in subfolders. For example, i want to place the file like app/views/application/messages/_validation_errors.html.erb and render it like render 'messages/validation_errors', but it doesn't work.
Is it possible to do something like that? Or maybe somebody can advise how to act.
Thank's.
Solution 1:[1]
If I'm understanding your folder structure correctly, you have an application folder, then a messages subfolder? If so, try: render 'application/messages/validation_errors'
Solution 2:[2]
Regarding…
I want render 'messages/validation_errors' try to find partial in current folder (views/article/edit) and if its not exists in application folder
… this might do the trick:
class ApplicationController < ActionController::Base
before_action :_append_view_path
def _append_view_path
["app/views/#{controller_path}", 'app/views/application'].uniq.each do |extra_path|
append_view_path(extra_path)
end
end
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | heyitsjhu |
| Solution 2 | LeEnno |
