Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the default view path in Rails?

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 ?

like image 569
Hartator Avatar asked May 30 '11 15:05

Hartator


2 Answers

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.

like image 173
Jits Avatar answered Sep 24 '22 22:09

Jits


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

like image 23
bor1s Avatar answered Sep 24 '22 22:09

bor1s