Forum: Ruby on Rails question about dynamic layout

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7da4a7b5be7f1e115861a253afb80641?d=identicon&s=25 gmoniey@gmail.com (Guest)
on 2007-05-12 04:08
(Received via mailing list)
Hi,

I have implemented a method where javascript would be found in an
index file, and depending on the result, a session variable would be
set to determine the layout the user is to use.

Now heres the problem. Not only does javascript determine the layout,
but the user can manually force 1 layout versus another. so think of
this process:

user goes to mysite.com/index (javascript determines which layout to
use, for this case, lets say it uses layout2)

user then manually goes to mysite.com/layout1 (layout1 is set in the
session variable and used)

up to this point, everything is working fine, but imagine if the user
click back, and then clicks on a link, from the users perspective, it
would seem like layout2 would be used, since thats the layout that was
used when the link was clicked on, but since layout1 was the last set
session variable, it will be used instead.

i want to avoid this problem, so i have been trying to figure out a
way to pass the layout mode as a params value (i.e. mysite.com/page?
layout=1). Is this a good idea? is there was another way to do this?
Ba3a00606eb530dcab2c4a6a59bf366d?d=identicon&s=25 Alain Ravet (Guest)
on 2007-05-12 13:45
(Received via mailing list)
gmoniey

   <big snip>
   > i want to avoid this problem, so i have been trying to figure out a
   > way to pass the layout mode as a params value (i.e.
mysite.com/page?
   > layout=1). Is this a good idea? is there was another way to do
this?


I don't understand your question but here is my answer :

in the controller :
-------------------
  ..
  layout  proc {|controller|
    if controller.action_name
        conditon = ....
        condition ? 'layout_1' : 'layout_2'
    else
      'layout_3'
    end
  }
  ..

Alain Ravet
--------
blog.ravet.com/
7da4a7b5be7f1e115861a253afb80641?d=identicon&s=25 gmoniey@gmail.com (Guest)
on 2007-05-13 23:38
(Received via mailing list)
Hi Alain,

i actually have something like that already, but here is the
problem....

lets imagine you go to mysite.com/page1 and that page sets the
condition so that layout1 is used (for all links on that page)...i.e.
lets say these is an "About" link...when it is clicked, layout1 is
used.....now, lets say the user navigates to mysite.com/page2 and that
page sets the condition so that layout2 is used.

here is where i feel my design is flawed....if the user is to click
the back button (i.e. goes back to mysite.com/page1) and clicks on a
link, layout2 is going to be used (since that is the last layout the
condition has been set to)....this is a mistake (in my mind), since i
think that layout1 should come up, since that is whats expected...

i have been thinkin about how to address this, and it seems that other
than using different explicit actions to define the layouts....or pass
the current layout as a parameter (although this will end up with ugly
URLs)....
This topic is locked and can not be replied to.