How can I set controller-wide layout and template?

Hi,

When you want to change the default layout and template, you can do the
following.

render :layout => “some_controller/my_layout” :template => “my_template”

I’m in a situation where I need to change the layout and template
dynamically according to the data from DB.
I want to set them for controller-wide instead of action-wide.
(In one place instead of many places)
How can I do that?

For example,

In view/boards/one, there are show.rhtml, list.rhtml, …
In view/boards/two, there are show.rhtml, list.rhtml, …

I want to change the location of templates dynamically.
This is sort of like theme change.

Layouts have the same issue.

Thanks in advance.

Sam

in your controller:

layout :choose_layout

def choose_layout
if Time.now.hour == 14
“two_pm_layout”
else
“other_layout”
end
end

Adam

Adam C. wrote:

in your controller:

layout :choose_layout

def choose_layout
if Time.now.hour == 14
“two_pm_layout”
else
“other_layout”
end
end

Adam

Hi Adam,

Thanks for the answer.
Do you know how to dynamically change the location of template?
The template file name will be decided by the action name but the
location(directory) of the file should be dynamic.

Sam

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs