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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in your controller:
layout :choose_layout
def choose_layout
if Time.now.hour == 14
"two_pm_layout"
else
"other_layout"
end
end
Adam
On 8/22/07, Sam Kong
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> 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
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Adam Cohen wrote:> in your controller: > > layout :choose_layout > > def choose_layout > if Time.now.hour == 14 > "two_pm_layout" > else > "other_layout" > end > end > > AdamHi 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---