Yello, I''m setting my layout in a before_filter. Here is what I have in application.rb: before_filter :find_current_site layout $layout def find_current_site if blahblahblah $layout = "joe1" else $layout = "joe2" end end It''s working on my local mongrel server, but on my live server (also mongrel) I always end up with no layout, no matter how many times I refresh. Does anyone know what is going on here? -- 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 -~----------~----~----~----~------~----~------~--~---
I''m using Ubuntu, if that makes any difference at all. Anyone have a clue why this is happening? -- 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 -~----------~----~----~----~------~----~------~--~---
Hi,> I''m setting my layout in a before_filter. > > before_filter :find_current_site > > layout $layout > > def find_current_site > > It''s working on my local mongrel server, but on my live server (also > mongrel) I always end up with no layout, no matter how many times I > refresh. > > Does anyone know what is going on here? >yep.. when you are in development mode, the classes (most of them anyhow) get reloaded at each request. This means the code is reinterpreted every time and that''s why: a) you don''t need to restart so it''s cool to try things quickly, and: b) it''s much slower than running in production mode. When in production, the classes get interpreted when loaded, and they are not reinterpreted every time. That''s why you need to restart the server when you change the code. This means the class variables will keep their values between calls unless you modify them explicitely. So what''s going on is first time you reference your controller, variable $layout doesn''t have any value, so you get a nil there. Then no matter what you do, the nil is there between calls. There are different approaches to this, the most similar to your solution being just to use a proc instead of a value for the layout. You can say layout :find_current_site and then that method must return a String with the layout name. That should do the trick. Also, using global variables is generally speaking a bad idea if you want to make solid modular code, so I''d try to avoid them when possible. regards, javier ramirez --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks a bunch, that did the trick. -- 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 -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-30 17:41 UTC
Re: Difference between local and live server...
Use an instance variable. Global variables are a bad idea in general, and especially in rails there is no need for them. One of the reasons we have before_filters is to obviate the need for global variables. On Aug 30, 10:56 am, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Yello, > > I''m setting my layout in a before_filter. > > Here is what I have in application.rb: > before_filter :find_current_site > > layout $layout > > def find_current_site > > if blahblahblah > $layout = "joe1" > else > $layout = "joe2" > end > > end > > It''s working on my local mongrel server, but on my live server (also > mongrel) I always end up with no layout, no matter how many times I > refresh. > > Does anyone know what is going on here? > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
rein.henrichs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Aug-30 17:42 UTC
Re: Difference between local and live server...
Also, if you''re using this for a layout, you can simply do layout :find_current_site and it will use the return value to determine the layout. On Aug 30, 12:41 pm, rein.henri...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> Use an instance variable. Global variables are a bad idea in general, > and especially in rails there is no need for them. One of the reasons > we have before_filters is to obviate the need for global variables. > > On Aug 30, 10:56 am, Joe Peck <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> > wrote: > > > Yello, > > > I''m setting my layout in a before_filter. > > > Here is what I have in application.rb: > > before_filter :find_current_site > > > layout $layout > > > def find_current_site > > > if blahblahblah > > $layout = "joe1" > > else > > $layout = "joe2" > > end > > > end > > > It''s working on my local mongrel server, but on my live server (also > > mongrel) I always end up with no layout, no matter how many times I > > refresh. > > > Does anyone know what is going on here? > > -- > > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
unknown wrote:> Also, if you''re using this for a layout, you can simply do > > layout :find_current_site > > and it will use the return value to determine the layout.That''s actually exactly what I''m doing :) -- 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 -~----------~----~----~----~------~----~------~--~---