Posted 13 days ago. Visible to the public.

Rails: Adding view paths on the fly

Rails offers a way to prepend (or append) view paths just for the current request.


A use case of this is a different set of view templates that should be used under certain circumstances:

class SomeController < ApplicationController before_action :prepare_views # ... private def prepare_views if <condition> prepend_view_path Rails.root.join('app', 'views', 'special') end end end

If <condition> is true, Rails will first look into app/views/special to find a view template. If the desired template does not exist there, it will fall back to its standard view paths. This way you can customize select templates without needing to redefine all.

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Author of this card:

Dominik Schöler
Last edit:
13 days ago
by Dominik Schöler
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Dominik Schöler to makandra dev