5

I want to be able to change dynamically the view folder. The aim is to be able to change completely the web design depending on the request. I am thinking about something like this :

 Class PagesController

     default_views_path(current_theme_path)

     def show
         Blablah...
     end

 end

Supposing a directory architecture like this :

 -apps
 --views
 ---theme 1/show.html.erb
 ---theme 2/show.html.erb
 ---theme 3/show.html.erb

I search over the web and I have found preprend_view_path. (:deprecated) Do you think this is a good idea ot use this ? Any feedback ?

EDIT

In fact, I want to simplify this :

 Class PagesController

     def show
         render "#{current_theme}/show"
     end

     def edit
         render "#{current_theme}/edit"
     end

     def list
         render "#{current_theme}/list"
     end

     def index
         render "#{current_theme}/index"
     end

 end

Any Solutions ?

Hartator
  • 5,029
  • 4
  • 43
  • 73

2 Answers2

4

You could use append_view_path. In fact, there is a comment on this append_view_path page where someone has used it for theming.

Jits
  • 9,647
  • 1
  • 34
  • 27
1

Maybe you should use layout :some_method_to_change_theme instead? This will simplify and will keep your views DRY.
Look at this layout

bor1s
  • 4,081
  • 18
  • 25
  • layout works only for changing the layout, but not for changing the yielded templates themselves. Still a good point to not forget that. – Almaron Jun 10 '16 at 18:27