Sometimes you need to break rails’ conventions a little bit and set custom path for all templates per controller. Especially for the purpose of namespacing.
For example, you have a controller:
By default, rails will search for templates in
But what if you want to put those templates in
Instead of this:
You can do this:
However, this will break controller’s spec.
There is another way to do this, however, with another limitation:
Now rails will search for templates in
app/views/users/user_groups. The limitation is that you must name a folder for your templates like a controller. For example, you cannot use
app/views/users/groups as a folder for templates for
UserGroupsController. You must name this folder
app/views/users/user_groups because of the controller’s name.
There are couple ways to set custom templates path per controller. Both have their downsides as a price for breaking conventions.